Example usage for javax.swing JTextPane getHighlighter

List of usage examples for javax.swing JTextPane getHighlighter

Introduction

In this page you can find the example usage for javax.swing JTextPane getHighlighter.

Prototype

public Highlighter getHighlighter() 

Source Link

Document

Fetches the object responsible for making highlights.

Usage

From source file:Main.java

public Main() {
    setSize(300, 200);/*from   w  ww . j av  a  2s  . co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    final JTextPane textPane = new JTextPane();
    add(textPane);
    textPane.addCaretListener(new CaretListener() {
        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());
            }

        }
    });
}