How to use glassPane to blocking and redispacting mouse event
1 posts in topic
Flat View  Flat View

Posted By:   Sagar_G
Posted On:   Thursday, May 12, 2005 03:51 AM

i had made one panel which is shown on layeredpane's popup layer , i want to use glass pane to trap mouse event outside this panel and block them , but dispatch mouse event on that panel properly to that panel..........

Re: How to use glassPane to blocking and redispacting mouse event

Posted By:   Almagest_FUTT  
Posted On:   Wednesday, May 18, 2005 12:12 AM


first, of course, getGlassPane().setVisible(true) (set it visible(false) when you're finished).

be glassPane the GlassPane.

be panel your panel.

Add a MouseListener to glassPane (i don't think you'll ever need to remove it), in each of which's methods you do something like that:

void checkEvent(MouseEvent e){
Point p = e.getPoint();
p = SwingUtilities.convertPoint(glassPane, p.x, p.y, panel);

if( panel.contains(p) ){
Component target = SwingUtilities.getDeepestComponentAt(panel, p.x, p.y);
if(target!=null){ //be safe
MouseEvent newEvent = SwingUtilities.convertMouseEvent(glassPane, e, target);

e.consume(); // <- important

That should do it.
About | Sitemap | Contact