Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2645
| From | "Steve W. Jackson" <steve.w..jackson@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Menu Removes Focus |
| Message-ID | <stevewjackson-FCB388.14163415102007@individual.net> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1192199555.846573.118100@v29g2000prd.googlegroups.com> |
| Date | 2011-04-27 15:40 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui,comp.l In article <1192199555.846573.118100@v29g2000prd.googlegroups.com>, Jason Cavett <jason.cavett@gmail.com> wrote: > 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 = -- Steve W. Jackson Montgomery, Alabama --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Find similar | Unroll thread
Menu Removes Focus "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000 Re: Menu Removes Focus "Steve W. Jackson" <steve.w..jackson@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000
csiph-web