This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Events from inner components. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Events from inner components." Watch "Events from inner components." New topic
Author

Events from inner components.

Jarosław Piotrowski
Greenhorn

Joined: Jul 22, 2009
Posts: 5
Hi there...
Im having a problem, let me explain it by example:

I have some JInternalFrames on JLayeredPane... and i want every of them to go to front when selected. The problem is, that if my JInternalFrame has any focusable component in it and user clicks on that component, JInternalFrame loses focus and is not getteing focus events any more - even if i click on its bar. I tried also listening for mouse events, but it also doesnt notify my JInternalFrame when inner component is clicked.

So is there any way I can know about any mouse/focus event on anything in my JInternalFrame or I have to add focus/mouse listeners to every component in it?


Why the hell users are displayed as their first and last name...
Jarosław Piotrowski
Greenhorn

Joined: Jul 22, 2009
Posts: 5
Ok, i did it like this:
Every JInternalFrame has custom glasspane on it. this glass pane captures every mouse event and redispatch for component which is under the point of event (x,y) - if current component is different than last, additionaly mouseexit and mouseenter events are called.

If anyone wants to know more, ask here or e-mail me.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
not sure I'm reading the problem right, but one possible way to do it:

add an AWTEventListener, listening for mousePressed
use SwingUtilities.getAncestorOfClass(..) to check for a JInternalFrame
if not null, set that JInternalFrame to selected(true)

[EDIT]
probably better to use mouseReleased
 
jQuery in Action, 2nd edition
 
subject: Events from inner components.
 
Similar Threads
JInternalFrames and focus
Popup on titlebar of JInternalFrame
what if i dont like where mouse gets clicked
mnemonics are not getting focus for the menubar
JInternalFrame to get Focus