Example usage for javax.swing JTextArea setCaret

List of usage examples for javax.swing JTextArea setCaret

Introduction

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

Prototype

@BeanProperty(expert = true, description = "the caret used to select/navigate")
public void setCaret(Caret c) 

Source Link

Document

Sets the caret to be used.

Usage

From source file:CornerCaret.java

public static void main(String args[]) {
    JFrame frame = new JFrame("CornerCaret demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea area = new JTextArea(8, 32);
    area.setCaret(new CornerCaret());
    area.setText("This is the story\nof the hare who\nlost his spectacles.");
    frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    frame.pack();/*  www .j a  v a2  s  .c  o  m*/
    frame.setVisible(true);
}

From source file:FancyCaret.java

public static void main(String args[]) {
    JFrame frame = new JFrame("FancyCaret demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea area = new JTextArea(8, 32);
    area.setCaret(new FancyCaret());
    area.setText("VI\tVirgin Islands \nVA      Virginia\nVT\tVermont");
    frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    frame.pack();//from   ww  w  .j a v  a  2s.  c o  m
    frame.setVisible(true);
}

From source file:LineHighlightPainter.java

public static void main(String args[]) {

    // extend DefaultCaret as an anonymous inner class
    Caret lineHighlightPainterCaret = new DefaultCaret() {
        private Highlighter.HighlightPainter lhp = new LineHighlightPainter();

        // override getSelectionPainter to return the LineHighlightPainter
        protected Highlighter.HighlightPainter getSelectionPainter() {
            return lhp;
        }/*from w  w w. j  ava 2 s. c o m*/
    };

    JFrame frame = new JFrame("LineHighlightPainter demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea area = new JTextArea(9, 45);
    area.setCaret(lineHighlightPainterCaret);
    area.setLineWrap(true);
    area.setWrapStyleWord(true);
    area.setText("This is the story\nof the hare who\nlost his spectacles.");
    frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JTextArea textArea = new JTextArea();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    DefaultCaret caret = new DefaultCaret() {
        @Override//from  www.j av  a2  s .  c o m
        public boolean isSelectionVisible() {
            return true;
        }
    };
    textArea.setCaret(caret);
    textArea.setFont(new java.awt.Font("Miriam Fixed", 0, 13));

    Color color = Color.BLUE;
    // textArea.setBackground(color);
    textArea.setSelectedTextColor(color);
    f.getContentPane().add(new JScrollPane(textArea));
    f.pack();
    f.setVisible(true);
}