javax.swing.text.AttributeSet.containsAttributes()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(28)

本文整理了Java中javax.swing.text.AttributeSet.containsAttributes()方法的一些代码示例,展示了AttributeSet.containsAttributes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AttributeSet.containsAttributes()方法的具体详情如下:
包路径:javax.swing.text.AttributeSet
类名称:AttributeSet
方法名:containsAttributes

AttributeSet.containsAttributes介绍

暂无

代码示例

代码示例来源:origin: omegat-org/omegat

private void refreshPane() {
  final int docLength = doc.getLength();
  if (docLength == 0) {
    return;
  }
  try {
    // clear attributes
    for (int i = 0; i < docLength; ++i) {
      if (doc.getCharacterElement(i).getAttributes().containsAttributes(LINK_ATTRIBUTES)) {
        doc.setCharacterAttributes(i, 1, DEFAULT_ATTRIBUTES, true);
      }
    }
    // URL detection
    final String text = doc.getText(0, docLength);
    final Matcher matcher = URL_PATTERN.matcher(text);
    while (matcher.find()) {
      final int offset = matcher.start();
      final int targetLength = matcher.end() - offset;
      try {
        // Transform into clickable text
        AttributeSet atts = makeAttributes(offset, new URI(matcher.group()));
        doc.setCharacterAttributes(offset, targetLength, atts, true);
      } catch (URISyntaxException ex) {
        Log.log(ex);
      }
    }
  } catch (BadLocationException ex) {
    Log.log(ex);
  }
}

代码示例来源:origin: stackoverflow.com

import javax.swing.JTextPane;
import javax.swing.text.StyleConstants;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;

public class StyleBugFix {
  public static void main(String[] args) {

    JTextPane textPane = new JTextPane();
    textPane.setText("This is a test string");

    StyleConstants.setBold(BOLD, true);

    StyleConstants.setItalic(ITALIC, true);

    int start = 5;
    int end = 10;

    textPane.getStyledDocument().setCharacterAttributes(start, end - start, BOLD, false);
    textPane.getStyledDocument().setCharacterAttributes(start, end - start, ITALIC, false);
    for(int i = start; i < end; i++)
      System.out.println(textPane.getStyledDocument().getCharacterElement(i).getAttributes()
        .containsAttributes(BOLD)); //all now print true
  }

  private static final MutableAttributeSet BOLD = new SimpleAttributeSet();
  private static final MutableAttributeSet ITALIC = new SimpleAttributeSet();
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

if( tokenElem.getAttributes().containsAttributes( _error ) ||
  tokenElem.getAttributes().containsAttributes( _warning ) )

相关文章