Forums Register Login

Basic Questions regarding JButton

+Pie Number of slices to send: Send
As I understand the Swing architecture:
1) ActionListeners can be registered using JButton.addActionListener
2) Implicitly, the JButton has registered with the DefaultButtonModel as an Action Listener

Now when the user clicks the button
1) The DefaultButtonModel state will change, this causes an event to be queued on the EventQueue. The main thread is then relinquished
2) In the Event dispatcher thread, the JButton receives the event.

Now my question is:

Does the JButton in turn notify the listeners SYNCHRONOUSLY? or does it notify them by placing events again on the event queue?
+Pie Number of slices to send: Send
Rakkarn,

The JButton notifies the listeners SYNCHRONOUSLY. If you throw a runtime exception in the actionPerformed() of one of the listeners, none of the other listeners which have not been invoked yet will be invoked.

Just remember that the current thread that invokes the actionPerformed() method WILL be the event dispatcher thread, so you are safe to invoke GUI methods from the actionPerformed() method. But, be aware that if your actionPerformed() method takes a while, your GUI will appear to be frozen.
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 857 times.
Similar Threads
confusing synchronized??
How to avoid Deadlock (Wait with two locks)
a delegation event model
Parent class event listener
Threads and Listeners
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:49:57.