Search code examples
javaswingjtextarea

JTextArea making text invisible


I want my JTextArea to show only the caret. I've setted my JTextArea to not opaque but I couldn't hide the text. How do I achieve this

JTextArea text = new JTextArea();
text.setOpaque(false);//This doesn't make text transparent

Solution

  • This code:

    JTextArea a = new JTextArea();
    a.setText("hello, world!");
    a.setForeground(new Color(0, 0, 0, 0));
    

    seemed to work fine when I tested it, it made both set text and typed text invisible.