mithun1538
mithun1538

Reputation: 1477

how to select a line in a Jtextarea?

I have a jtextarea that is not editable. It has some text in it. What i want is that when a user clicks in the jtextarea, (preferably single click), the entire line be highlighted, and this highlighted text be retrieved.

Each line actually has an email of the form [email protected]. To select the entire text would require triple clicks. I want the email to be selected in a single click. Is this possible?

Upvotes: 0

Views: 3719

Answers (1)

Searles
Searles

Reputation: 1817

Sure. Just implement you own listener and call http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html#select%28int,%20int%29 on the JTextArea.

But wouldn't a JList not rather fit your requirements?

Upvotes: 4

Related Questions