Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Right Click does not make a selection. What is the easiest way to solve this globally?

Tags:

java

swing

Is there a way to globally make right click also select the element that you right click on?

From what I understand this has been a bug in Swing for a long time likely to never be fixed because at this point applications depend on it.

Any advice on doing this on a global scale? Perhaps on the L&F?

like image 416
drye Avatar asked Sep 11 '08 14:09

drye


1 Answers

Using the Glass Pane will do the trick.

Here's a tutorial on how to use the glass pane to get the right click button and redispatch it to the right component.


As the glass pane is not a solution in this case, I suggest you take a look at the Toolkit class. Specificaly the addAWTEventListener method. You can add a global event listener with it. To add a mouse event listener:

Toolkit.getDefaultToolkit().
        addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK);

Cheers

like image 61
Marcio Aguiar Avatar answered Oct 31 '22 04:10

Marcio Aguiar