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

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

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

JTextPane.getHighlighter介绍

暂无

代码示例

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

JTextPane textPane = new JTextPane(...);
DefaultHighlighter highlighter =  (DefaultHighlighter)textPane.getHighlighter();
highlighter.setDrawsLayeredHighlights(false);

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

public class TextPaneHighlightsDemo extends JFrame {

public TextPaneHighlightsDemo() {
  super("SplashScreen demo");
  setSize(300, 200);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  final JTextPane textPane = new  JTextPane();
  add(textPane);
  textPane.addCaretListener(new CaretListener() {

    @Override
    public void caretUpdate(CaretEvent e) {
      Highlight[] h = textPane.getHighlighter().getHighlights();
      for(int i = 0; i < h.length; i++) {
        System.out.println(h[i].getStartOffset());
        System.out.println(h[i].getEndOffset());
      }

    }
  });
    }

public static void main (String args[]) {
  TextPaneHighlightsDemo test = new TextPaneHighlightsDemo();
  test.setVisible(true);
}
}

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

jTextPane1.addCaretListener(new CaretListener() {
   public void caretUpdate(CaretEvent evt) {
     if(evt.getDot() == evt.getMark())return;
 JTextPane txtPane = (JTextPane) evt.getSource();
 DefaultHighlighter highlighter = (DefaultHighlighter) txtPane.getHighlighter();
 highlighter.removeAllHighlights();
 DefaultHighlightPainter hPainter = new DefaultHighlightPainter(new Color(0xFFAA00));
 String selText = txtPane.getSelectedText();
 String contText = "";// = jTextPane1.getText();
 DefaultStyledDocument document = (DefaultStyledDocument) txtPane.getDocument();
 try {
   contText = document.getText(0, document.getLength());
 } catch (BadLocationException ex) {
   Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex);
 }
 int index = 0;
 while((index = contText.indexOf(selText, index)) > -1){
   try {
     highlighter.addHighlight(index, selText.length()+index, hPainter);
     index = index + selText.length();
   } catch (BadLocationException ex) {
     Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex);
     //System.out.println(index);
   }
   }
   }
 });

代码示例来源:origin: antlr/codebuff

@Override
  public void caretUpdate(CaretEvent e) {
    int cursor = e.getDot();
    JTextPane textPane = (JTextPane)e.getSource();
    TokenPositionAnalysis analysis = getAnalysisForCharIndex(cursor);
    Highlighter highlighter = textPane.getHighlighter();
    HighlightPainter painter = new DefaultHighlightPainter(Color.orange);
    try {
      highlighter.removeAllHighlights();
      if ( analysis!=null ) {
        highlighter.addHighlight(analysis.charIndexStart, analysis.charIndexStop+1, painter);
      }
      scope.injectNLConsole.setText(analysis!=null ? analysis.wsAnalysis : "");
      scope.injectNLConsole.setCaretPosition(0);
      scope.alignConsole.setText(analysis!=null ? analysis.alignAnalysis : "");
      scope.alignConsole.setCaretPosition(0);
    }
    catch (Exception ex) {
      ex.printStackTrace(System.err);
    }
  }
}

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

pane.setFocusable(true);
pane.setText("This is some text. I am making an SSCCE. This is some additional text.");
pane.getHighlighter().addHighlight(2, 30,
    new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY));
scrollPane = new JScrollPane(pane);

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

} else {
  try {
    Highlighter highlighter = tcomp.getHighlighter();
    highlighter.addHighlight(currentStart, currentEnd, highlighterCurrent);
    scrollToCurrent();

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

Highlighter highlighter = tcomp.getHighlighter();
if (cancel) {
  highlighter.removeAllHighlights();

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

String txt = tcomp.getText();
Matcher matcher = pattern.matcher(txt);
Highlighter highlighter = tcomp.getHighlighter();
int lastStart = -1;
int lastEnd = -1;

代码示例来源:origin: zzhang5/zooinspector

this.setLayout(new BorderLayout());
this.dataArea = new JTextPane();
this.highlighter = (DefaultHighlighter) dataArea.getHighlighter();

相关文章

JTextPane类方法