Menu Removes Focus

J

Jason Cavett

I'm curious - how do I know what component has focus when I need to
pop up a menu to complete a task.

For example, in my JTree, I have a popup menu that comes up when I
right click on the tree. Well, the JTree is the "real" object that
has focus (for a paste/cut/copy/whatever), but now that the menu is
shown, Java thinks it is the thing to have the real focus.

Hopefully that makes sense.


Thanks
 
S

Steve W. Jackson

Jason Cavett said:
I'm curious - how do I know what component has focus when I need to
pop up a menu to complete a task.

For example, in my JTree, I have a popup menu that comes up when I
right click on the tree. Well, the JTree is the "real" object that
has focus (for a paste/cut/copy/whatever), but now that the menu is
shown, Java thinks it is the thing to have the real focus.

Hopefully that makes sense.


Thanks

The popup really is the item with "real" focus in this case. Only one
component at any time can have "the focus" in your application. When a
popup is displayed, it's a window of a sort and deactivates the one
containing your tree. But you'll find in the API for Window (one of the
superclasses to JDialog and JFrame) that there's a method named
getMostRecentFocusOwner which will identify the Component owning the
focus when the window regains focus.

HTH,
= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top