Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextArea show Caret while setEditable is false

How can I put Caret in JTextArea while setEditable is disabled?

A sample code when I need Caret to be visible:

public void run(){
    JFrame frame = new JFrame();
    JTextArea text = new JTextArea();
    text.setEditable(false);
    String line = "added line";
    text.append(line);
    text.setCaretPosition(text.getCaretPosition() + line.length());

    frame.getContentPane().add(text);
    frame.setSize(300,300);
    frame.setVisible(true);
}

What I want to achieve is that, when the user types within TextArea, characters must not be displayed. Typed characters are redirected to OutputStream and appropriate InputStream is received which will be displayed within TextArea. This works fine, but Caret is hidden because of setEditable(false).

like image 906
Tornike Avatar asked Aug 30 '11 12:08

Tornike


1 Answers

text.getCaret().setVisible(true) and/or text.getCaret().setSelectionVisible(true)

like image 161
StanislavL Avatar answered Sep 28 '22 09:09

StanislavL