Example usage for javax.swing JTextArea getHighlighter

List of usage examples for javax.swing JTextArea getHighlighter

Introduction

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

Prototype

public Highlighter getHighlighter() 

Source Link

Document

Fetches the object responsible for making 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]);
        }//  www .ja  v a  2s  . c o m
    }
    highlight(textComp);
}

From source file:Main.java

public static void main(String args[]) {
    JTextArea area = new JTextArea(5, 20);
    area.setText("this is a test.");
    String charsToHighlight = "aeiouAEIOU";
    Highlighter h = area.getHighlighter();
    h.removeAllHighlights();//from  www .j  a va 2  s.c om
    String text = area.getText().toUpperCase();
    for (int i = 0; i < text.length(); i += 1) {
        char ch = text.charAt(i);
        if (charsToHighlight.indexOf(ch) >= 0)
            try {
                h.addHighlight(i, i + 1, DefaultHighlighter.DefaultPainter);
            } catch (Exception ble) {
            }
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("MultiHighlight");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea comp = new JTextArea(5, 20);
    comp.setText("this is a test");
    frame.getContentPane().add(new JScrollPane(comp), BorderLayout.CENTER);

    String charsToHighlight = "a";
    Highlighter h = comp.getHighlighter();
    h.removeAllHighlights();/*from   ww  w .  jav  a2s  . c o m*/
    String text = comp.getText().toUpperCase();

    for (int j = 0; j < text.length(); j += 1) {
        char ch = text.charAt(j);
        if (charsToHighlight.indexOf(ch) >= 0)
            h.addHighlight(j, j + 1, DefaultHighlighter.DefaultPainter);
    }
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    JTextArea area = new JTextArea(5, 20);
    area.setText("this is a test.");
    String charsToHighlight = "aeiouAEIOU";
    Highlighter h = area.getHighlighter();
    h.removeAllHighlights();/*  w ww . jav  a2  s.  c  o m*/
    String text = area.getText().toUpperCase();
    for (int i = 0; i < text.length(); i += 1) {
        char ch = text.charAt(i);
        if (charsToHighlight.indexOf(ch) >= 0)
            try {
                h.addHighlight(i, i + 1, DefaultHighlighter.DefaultPainter);
            } catch (Exception ble) {
            }
    }
    this.getContentPane().add(area);

}

From source file:coreferenceresolver.gui.MarkupGUI.java

private JScrollPane newReviewPanel(Review review, int reviewId) throws BadLocationException {
    //Model/*from  ww w.  jav a 2 s .  c  o  m*/
    ReviewElement reviewElement = new ReviewElement();

    ScrollablePanel reviewPanel = new ScrollablePanel();
    reviewPanel.setLayout(new BoxLayout(reviewPanel, BoxLayout.PAGE_AXIS));

    JTextField title = new JTextField("NEW REVIEW " + reviewId);
    title.setBackground(Color.pink);

    reviewPanel.add(title);

    JTextArea reviewContentTxtArea = new JTextArea();
    reviewContentTxtArea.setLineWrap(true);
    reviewContentTxtArea.setWrapStyleWord(true);
    reviewContentTxtArea.setEditable(false);
    reviewContentTxtArea.setText(review.getRawContent());

    int chainId = 0;
    for (CorefChain cc : review.getCorefChains()) {
        for (int npId : cc.getChain()) {
            NounPhrase np = review.getNounPhrases().get(npId);
            Object highlighTag = reviewContentTxtArea.getHighlighter().addHighlight(np.getOffsetBegin(),
                    np.getOffsetEnd() + 1, highlightPainters.get(chainId));
            this.markupReviews.get(reviewId).getNounPhrases().get(npId).highlighterTag = highlighTag;
        }
        ++chainId;
    }

    reviewPanel.add(reviewContentTxtArea);

    ScrollablePanel markupsPanel = new ScrollablePanel();
    markupsPanel.setLayout(new BoxLayout(markupsPanel, BoxLayout.PAGE_AXIS));

    for (int i = 0; i < review.getNounPhrases().size(); ++i) {
        JScrollPane newMarkupPanel = newMarkupPanel(review.getNounPhrases().get(i), reviewElement);
        markupsPanel.add(newMarkupPanel);
    }

    JScrollPane scrollMarkupsPanel = new JScrollPane(markupsPanel);

    //Add Dimension for scrolling
    Dimension curScreenDimen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    scrollMarkupsPanel.setPreferredSize(new Dimension((int) curScreenDimen.getWidth() - 50, 400));

    reviewPanel.add(scrollMarkupsPanel);

    //MODEL
    reviewElement.reviewTextArea = reviewContentTxtArea;
    reviewElements.add(reviewElement);

    reviewPanel.add(new JSeparator(SwingConstants.HORIZONTAL));

    reviewPanel.add(Box.createVerticalStrut(20));

    JScrollPane scrollReviewPanel = new JScrollPane(reviewPanel);

    return scrollReviewPanel;
}