Jeff Storey
Jeff Storey

Reputation: 57192

Ignoring Java mouse events on AWT components that were generated from lightweight components

I have a JFileChooser that is opened on top of an AWT component (we use a GLCanvas for some openGL rendering). If I double click the icon in the file chooser to close it, the mouse clicks are passed to the GLCanvas. I have read that mouse events on the lightweight components will be passed to the heavyweight components, but is there a way to detect when this is happening? Double clicking on the GLCanvas performs another operation, which I would prefer not happen when the user is just double clicking to close the dialog.

Upvotes: 3

Views: 773

Answers (1)

Hunter McMillen
Hunter McMillen

Reputation: 61512

You could create event handlers for the mouse events on the lightweight components and then do nothing inside of them, that should stop the propagation to the heavier components.

Something like:

    public void mousePressed(MouseEvent e) {}

    public void mouseReleased(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {}

    public void mouseExited(MouseEvent e) {}

    public void mouseClicked(MouseEvent e) {}

Upvotes: 5

Related Questions