Example usage for javax.swing.text Highlighter getHighlights

List of usage examples for javax.swing.text Highlighter getHighlights

Introduction

In this page you can find the example usage for javax.swing.text Highlighter getHighlights.

Prototype

public Highlight[] getHighlights();

Source Link

Document

Fetches the current list of highlights.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea textComp = new JTextArea();

    Highlighter hilite = textComp.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();

    for (int i = 0; i < hilites.length; i++) {
        if (hilites[i].getPainter() instanceof MyHighlightPainter) {
            hilite.removeHighlight(hilites[i]);
        }/*from  www  .java  2s.co m*/
    }
    highlight(textComp);
}

From source file:Main.java

public static void removeHighlights(JTextComponent textComp) {
    Highlighter hilite = textComp.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();

    for (int i = 0; i < hilites.length; i++) {
        hilite.removeHighlight(hilites[i]);
    }//  ww  w .  j  a va  2  s .  c o  m
}

From source file:Main.java

public static void removeHightlights(final Highlighter.HighlightPainter sample, Highlighter highlighter) {
    for (Highlight highlight : highlighter.getHighlights()) {
        if (sample == highlight.getPainter()) {
            highlighter.removeHighlight(highlight);
        }//from  ww  w  . j av  a2  s  .  c  om
    }

}

From source file:Main.java

public static void removeHightlights(final Collection<Highlighter.HighlightPainter> sample,
        Highlighter highlighter) {
    for (Highlight highlight : highlighter.getHighlights()) {
        if (sample.contains(highlight.getPainter())) {
            highlighter.removeHighlight(highlight);
        }/*from w  ww . java2 s .c  o m*/
    }

}

From source file:Main.java

public static void removeHighlights(JTextComponent textComp) {
    Highlighter hilite = textComp.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();

    for (int i = 0; i < hilites.length; i++) {
        if (hilites[i].getPainter() instanceof MyHighlightPainter) {
            hilite.removeHighlight(hilites[i]);
        }/*from   www .j  ava 2s .c o  m*/
    }
}

From source file:Main.java

public static void removeHighlights(JTextComponent textComp) {
    Highlighter hilite = textComp.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();
    for (int i = 0; i < hilites.length; i++) {
        if (hilites[i].getPainter() instanceof Highlighter) {
            hilite.removeHighlight(hilites[i]);
        }//from w  ww .  j a  v a  2s  . c o m
    }
}

From source file:Main.java

public int search(String word) {
    int firstOffset = -1;
    Highlighter highlighter = comp.getHighlighter();
    Highlighter.Highlight[] highlights = highlighter.getHighlights();
    for (int i = 0; i < highlights.length; i++) {
        Highlighter.Highlight h = highlights[i];
        if (h.getPainter() instanceof UnderlineHighlightPainter) {
            highlighter.removeHighlight(h);
        }/*from  w  ww .  j  a  v  a 2s.  com*/
    }
    if (word == null || word.equals("")) {
        return -1;
    }
    String content = null;
    try {
        Document d = comp.getDocument();
        content = d.getText(0, d.getLength()).toLowerCase();
    } catch (BadLocationException e) {
        return -1;
    }
    word = word.toLowerCase();
    int lastIndex = 0;
    int wordSize = word.length();
    while ((lastIndex = content.indexOf(word, lastIndex)) != -1) {
        int endIndex = lastIndex + wordSize;
        try {
            highlighter.addHighlight(lastIndex, endIndex, painter);
        } catch (BadLocationException e) {
        }
        if (firstOffset == -1) {
            firstOffset = lastIndex;
        }
        lastIndex = endIndex;
    }
    return firstOffset;
}

From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java

private void removeHighlights() {
    Highlighter hilite = myMessageEditor.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();
    for (int i = 0; i < hilites.length; i++) {
        hilite.removeHighlight(hilites[i]);
    }/*ww w.  j  a  v a  2  s  .  c  om*/
}

From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java

private void removeMostHighlights() {
    Highlighter hilite = myMessageEditor.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();
    for (int i = 0; i < hilites.length - 2; i++) {
        hilite.removeHighlight(hilites[i]);
    }/*from  ww  w . j  av  a 2 s . c o  m*/
}

From source file:org.apache.cayenne.swing.components.textpane.JCayenneTextPane.java

public void removeHighlightText(Highlighter highlighter) {

    Highlighter.Highlight[] highlights = highlighter.getHighlights();
    for (int i = 0; i < highlights.length; i++) {
        Highlighter.Highlight h = highlights[i];
        if (h.getPainter() instanceof UnderlineHighlighterForText.UnderlineHighlightPainter) {
            highlighter.removeHighlight(h);
        }/* w w  w .  j a  v  a 2 s.  c  o  m*/
    }
}