It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Highlighting in JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Highlighting in JTextArea" Watch "Highlighting in JTextArea" New topic

Highlighting in JTextArea

Shane Roylance
Ranch Hand

Joined: Aug 29, 2001
Posts: 72
I am writing a text editor application. Right now its really basic with just a JTextArea, and a JMenuBar in a JDialog. The problem I have is if I highlight some text in the JTextArea, when I click on the menu bar the highlighting dissappears. I know it is a focus problem, but is there anything I can do to fix it or get around it?
Maybe I am going about this all wrong, any ideas??
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Just a shot in the dark here.
How about adding a MouseListener to the JTextArea and onMousePressed() try something like this:

I don't have time to test it right now - it's 1am over here in Europe.
Hope that helps,

Raising Flares debut album 'Ignition' out now

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
I agree. Here's the link:
subject: Highlighting in JTextArea
It's not a secret anymore!