• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea setSelection not highliting  RSS feed

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am having trouble with getting using setSelectionStart and setSelection end on a JTextField and on a JTextArea.

For the JTextFields, I click the left button on a mouse, and the program will highlight the word that the mouse is in. This works fine.



But if I use the right mouse button expecting the same result, the word is selected as I can use System.out.println to show the word on the console, but the word is not highlighted in the JTextField. Also, this is only when the right click is the first click into that component. What I mean is that if I left click into the component, and then right click, it works fine. How can I get this to work if the right click is the first click into the component?


For the JTextArea, I have a popup that shows up for the user to select a "Copy All" option. This should highlight all the text and copy the contents to the clipboard. The contents are copied to the clipboard but they are not highlighted. Please could someone give me some help to get this highlighted.



Many thanks!
Rachel
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try 'selectAll' in your 'else if(source == cpm.copyAllItem){' section.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Craig

I tried select(0, getText().length()) which didn't work, and selectAll() which also didn't work. Could the fact that I'm using the system l&f make any difference?

Cheers,
Rachel
[ May 25, 2005: Message edited by: Rachel Swailes ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!