Example usage for javax.swing.text Highlighter removeHighlight

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

Introduction

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

Prototype

public void removeHighlight(Object tag);

Source Link

Document

Removes a highlight from the view.

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  w  w w .ja  v  a  2  s . c  om*/
    }
    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]);
    }//from w w w .jav  a2s.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);
        }//ww  w.  j  a va 2 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);
        }// ww  w  .java2s  . c om
    }

}

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  .ja  va2  s . co  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   ww  w.ja  v a  2  s  .  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 av  a  2  s. c om
    }
    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]);
    }//from  w w  w.  j a  v  a2s.co m
}

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 w  w  w .j a  v a2  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);
        }/*from  w  ww . ja v a 2s.c  o m*/
    }
}