Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make JTextArea non-Selectable

Tags:

java

swing

i want to display a textarea decribing the value of a node ( a graph project) but whenever i select the text it gets messy so i want it to be unsectable ! this is the code :

public class TransparentTextArea extends JTextArea {

String texte;

public TransparentTextArea(String texte) {
    this.setLineWrap(true);
    this.setWrapStyleWord(true);
    this.texte = texte;
    this.setBackground(new Color(255, 0, 9, 0));
    this.setFont(new Font("Serif", Font.ITALIC, 24));
    this.setEditable(false);
    this.setText(texte);
    this.setSize(new Dimension(200,100 ));
  } 
}

thx

like image 365
Rad1 Avatar asked Sep 22 '12 17:09

Rad1


1 Answers

It's somehow old question but for those who still care, disabling the JTextArea is not very helpful, mostly because of the gray color of the foreground. The best thing to do, is to nullify the highlighter:

setHighlighter(null)
like image 76
Stelios Adamantidis Avatar answered Sep 23 '22 08:09

Stelios Adamantidis