Swing: Programmatically select a text
Posted
by HH
on Stack Overflow
See other posts from Stack Overflow
or by HH
Published on 2010-05-06T16:53:45Z
Indexed on
2010/05/06
16:58 UTC
Read the original article
Hit count: 170
Hey everyone,
I have a very simple Swing GUI with just a JTetxtArea. I am trying to programmatically select a part of text using:
textArea.select(startSelection,endSelection);
This work. However as soon as I add some other components to the GUI I do not see selection anymore
frame.getContentPane().add(button);
frame.getContentPane().add(textArea);
textArea.select(startSelection,endSelection);
I suspect that during layouting the gui, some event causes the text to be deselected. Am I right? And could anybody suggest a solution?
My goal is to have a program which displays a text, and allows the user to input start and end selection position, and a selection appears between these two position. Thank you.
© Stack Overflow or respective owner