javax.swing.JTextArea.getHighlighter()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(117)

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

JTextArea.getHighlighter介绍

暂无

代码示例

代码示例来源:origin: pmd/pmd

@Override
  public void run() {
    try {
      sourceCodeArea.getHighlighter().removeAllHighlights();
      if (node == null) {
        return;
      }
      int startOffset = sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1)
          + node.getBeginColumn() - 1;
      int end = sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) + node.getEndColumn();
      sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
          new DefaultHighlighter.DefaultHighlightPainter(HIGHLIGHT_COLOR));
      sourceCodeArea.moveCaretPosition(startOffset);
    } catch (BadLocationException exc) {
      throw new IllegalStateException(exc.getMessage());
    }
  }
});

代码示例来源:origin: fr.inria.wimmics/kggui

textAreaXMLResult.getHighlighter().addHighlight(tabStart.get(i), tabStop.get(i), DefaultHighlighter.DefaultPainter);

代码示例来源:origin: Wimmics/corese

textAreaXMLResult.getHighlighter().addHighlight(tabStart.get(i), tabStop.get(i), DefaultHighlighter.DefaultPainter);

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

class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {
    public MyHighlightPainter(Color color) {
      super(color);
    }   

  Highlighter.HighlightPainter myHighlightPainter = new MyHighlightPainter(Color.yellow);

  public void highlightt(JTextArea textComp, String pattern) {
    try {
      Highlighter hilite = textComp.getHighlighter();
      Document doc = textComp.getDocument();
      String text = doc.getText(0, doc.getLength());
      int pos = 0;

      while((pos=text.toUpperCase().indexOf(pattern.toUpperCase(),pos))>=0) {

        hilite.addHighlight(pos, pos+pattern.length(), myHighlightPainter);
        pos +=pattern.length();
      }
    } catch(Exception e) {
      e.printStackTrace();
    }   
  }

} // close class

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

hilit = userField.getHighlighter();
hilit.removeAllHighlights();

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

txtInform.getHighlighter().removeAllHighlights();
try {
  txtInform.getHighlighter().addHighlight(offset, offset + length, painter);
} catch (BadLocationException ble) {
  ble.printStackTrace();

代码示例来源:origin: com.github.gumtreediff/client.diff

private void updateJTreeAndJTextArea(ITree sel, JTextArea selJTextArea, boolean isMapped,
                   ITree match, TreePanel matchTreePanel,
                   JTextArea matchJTextArea) throws BadLocationException {
  selJTextArea.getHighlighter().removeAllHighlights();
  selJTextArea.getHighlighter().addHighlight(sel.getPos(), sel.getEndPos(), DefaultHighlighter.DefaultPainter);
  selJTextArea.setCaretPosition(sel.getPos());
  if (isMapped) {
    DefaultMutableTreeNode node = matchTreePanel.getTrees().get(match);
    matchTreePanel.getJTree().scrollPathToVisible(new TreePath(node.getPath()));
    matchTreePanel.getJTree().setSelectionPath(new TreePath(node.getPath()));
    matchJTextArea.getHighlighter().removeAllHighlights();
    matchJTextArea.getHighlighter().addHighlight(
        match.getPos(), match.getEndPos(), DefaultHighlighter.DefaultPainter);
    matchJTextArea.setCaretPosition(match.getPos());
  } else {
    matchTreePanel.getJTree().clearSelection();
    matchJTextArea.getHighlighter().removeAllHighlights();
  }
}

代码示例来源:origin: GumTreeDiff/gumtree

private void updateJTreeAndJTextArea(ITree sel, JTextArea selJTextArea, boolean isMapped,
                   ITree match, TreePanel matchTreePanel,
                   JTextArea matchJTextArea) throws BadLocationException {
  selJTextArea.getHighlighter().removeAllHighlights();
  selJTextArea.getHighlighter().addHighlight(sel.getPos(), sel.getEndPos(), DefaultHighlighter.DefaultPainter);
  selJTextArea.setCaretPosition(sel.getPos());
  if (isMapped) {
    DefaultMutableTreeNode node = matchTreePanel.getTrees().get(match);
    matchTreePanel.getJTree().scrollPathToVisible(new TreePath(node.getPath()));
    matchTreePanel.getJTree().setSelectionPath(new TreePath(node.getPath()));
    matchJTextArea.getHighlighter().removeAllHighlights();
    matchJTextArea.getHighlighter().addHighlight(
        match.getPos(), match.getEndPos(), DefaultHighlighter.DefaultPainter);
    matchJTextArea.setCaretPosition(match.getPos());
  } else {
    matchTreePanel.getJTree().clearSelection();
    matchJTextArea.getHighlighter().removeAllHighlights();
  }
}

代码示例来源:origin: net.sourceforge.pmd/pmd-core

@Override
  public void run() {
    try {
      sourceCodeArea.getHighlighter().removeAllHighlights();
      if (node == null) {
        return;
      }
      int startOffset = sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1)
          + node.getBeginColumn() - 1;
      int end = sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) + node.getEndColumn();
      sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
          new DefaultHighlighter.DefaultHighlightPainter(HIGHLIGHT_COLOR));
      sourceCodeArea.moveCaretPosition(startOffset);
    } catch (BadLocationException exc) {
      throw new IllegalStateException(exc.getMessage());
    }
  }
});

相关文章

JTextArea类方法