Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing register to event type

Tags:

java

swing

In Java Swing I can register a listener to a certain gui event as follows

guiElement.addMouseListener(myListener);

but what if I want to automatically register to all the mouse events in my GUI application?
should I register myListener to each element?
In other words what I am looking for is something like

myListener.registerToEventType(MouseEvent.class)

Any idea?
Thank you

like image 835
mottalrd Avatar asked Apr 30 '13 09:04

mottalrd


1 Answers

but what if I want to automatically register to all the mouse events in my GUI application?

@see AWTEventListener, there are Mouse & Key Events

should I register myListener to each element?

yes is better than to redirect, consume or using SwingUtilities for apply MouseEvents to the derised JComponets, notice code could be longer than annonymous listener added to each of JComponents separatelly

like image 181
mKorbel Avatar answered Sep 29 '22 14:09

mKorbel