Have a look at this demo, it shows how to pass click events from the glass pane (where you paint your extra content) to the underlying "real" pane (where you want the clicks/events to happen). See the method redispatchMouseEvent
. Some relevant parts of the code are below:
glass = new FixedGlassPane(jFrame.getContentPane());
jFrame.setGlassPane(glass);
public class FixedGlassPane extends JPanel
...
addMouseListener(this);
addMouseMotionListener(this);
addFocusListener(this);
...
}
public void mouseDragged(MouseEvent e) {
if (needToRedispatch)
redispatchMouseEvent(e);
}
public void mouseMoved(MouseEvent e) {
if (needToRedispatch)
redispatchMouseEvent(e);
}
... other mouse event methods ...
private void redispatchMouseEvent(MouseEvent e) {
boolean inButton = false;
boolean inMenuBar = false;
Point glassPanePoint = e.getPoint();
Component component = null;
Container container = contentPane;
Point containerPoint = SwingUtilities.convertPoint(this,
glassPanePoint, contentPane);
int eventID = e.getID();
if (containerPoint.y < 0) {
inMenuBar = true;
container = menuBar;
containerPoint = SwingUtilities.convertPoint(this, glassPanePoint,
menuBar);
testForDrag(eventID);
}
//XXX: If the event is from a component in a popped-up menu,
//XXX: then the container should probably be the menu's
//XXX: JPopupMenu, and containerPoint should be adjusted
//XXX: accordingly.
component = SwingUtilities.getDeepestComponentAt(container,
containerPoint.x, containerPoint.y);
if (component == null) {
return;
} else {
inButton = true;
testForDrag(eventID);
}
if (inMenuBar || inButton || inDrag) {
Point componentPoint = SwingUtilities.convertPoint(this,
glassPanePoint, component);
component.dispatchEvent(new MouseEvent(component, eventID, e
.getWhen(), e.getModifiers(), componentPoint.x,
componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
}
}
private void testForDrag(int eventID) {
if (eventID == MouseEvent.MOUSE_PRESSED) {
inDrag = true;
}
}
}