Example usage for javax.swing.text DefaultHighlighter.DefaultHighlightPainter DefaultHighlighter.DefaultHighlightPainter

List of usage examples for javax.swing.text DefaultHighlighter.DefaultHighlightPainter DefaultHighlighter.DefaultHighlightPainter

Introduction

In this page you can find the example usage for javax.swing.text DefaultHighlighter.DefaultHighlightPainter DefaultHighlighter.DefaultHighlightPainter.

Prototype

public DefaultHighlightPainter(Color c) 

Source Link

Document

Constructs a new highlight painter.

Usage

From source file:eu.ggnet.dwoss.util.HtmlDialog.java

private void search() {
    try {//from w w  w . java2  s .  co  m
        Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);

        documentTextPane.getHighlighter().removeAllHighlights();
        StyledDocument styledDocument = documentTextPane.getStyledDocument();
        String text = styledDocument.getText(0, styledDocument.getLength());

        if (StringUtils.isBlank(text) || StringUtils.isBlank(searchField.getText()))
            return;
        int indexOf = text.indexOf(searchField.getText());

        if (indexOf == -1)
            JOptionPane.showMessageDialog(this, "Nichts gefunden.");
        while (indexOf != -1) {
            try {
                documentTextPane.getHighlighter().addHighlight(indexOf,
                        indexOf + searchField.getText().length(), painter);
                indexOf = text.indexOf(searchField.getText(), indexOf + 1);
            } catch (BadLocationException ex) {
                Logger.getLogger(HtmlDialog.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } catch (BadLocationException ex) {
        Logger.getLogger(HtmlDialog.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:components.TextFieldDemo.java

public TextFieldDemo() {
    initComponents();//from w ww.j  av  a  2 s. c  om

    InputStream in = getClass().getResourceAsStream("content.txt");
    try {
        textArea.read(new InputStreamReader(in), null);
    } catch (IOException e) {
        e.printStackTrace();
    }

    hilit = new DefaultHighlighter();
    painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
    textArea.setHighlighter(hilit);

    entryBg = entry.getBackground();
    entry.getDocument().addDocumentListener(this);

    InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = entry.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
    am.put(CANCEL_ACTION, new CancelAction());
}

From source file:pl.otros.logview.gui.message.update.MessageUpdateUtils.java

private static void markSearchResult(List<MessageFragmentStyle> searchResultPositions,
        OtrosJTextWithRulerScrollPane<? extends JTextComponent> otrosJTextWithRulerScrollPane) {
    RulerBarHelper.clearMarkers(otrosJTextWithRulerScrollPane);
    otrosJTextWithRulerScrollPane.getjTextComponent().getHighlighter().removeAllHighlights();
    Highlighter.HighlightPainter highlighter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);

    for (MessageFragmentStyle mfs : searchResultPositions) {
        int position = mfs.getOffset();
        RulerBarHelper.addTextMarkerToPosition(otrosJTextWithRulerScrollPane, position, "Search result",
                Color.YELLOW.darker().darker().darker(), RulerBarHelper.TooltipMode.LINE_NUMBER_PREFIX);
        try {//from  ww w .  j av a  2  s  .c  o  m
            otrosJTextWithRulerScrollPane.getjTextComponent().getHighlighter().addHighlight(mfs.getOffset(),
                    mfs.getLength() + mfs.getOffset(), highlighter);
        } catch (BadLocationException e) {
            LOGGER.log(Level.SEVERE, "Cant get text of log detail view for highlighting search result", e);
        }
    }
    LOGGER.finest("Update with chunks finished");
}