开发者

how to select a line in a Jtextarea?

开发者 https://www.devze.com 2022-12-26 19:06 出处:网络
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 highlighte

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 t开发者_Go百科he form name@emailid.com. To select the entire text would require triple clicks. I want the email to be selected in a single click. Is this possible?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消