| Author |
JButton disabling mouse listeners
|
Zak Nixon
Ranch Hand
Joined: Sep 27, 2003
Posts: 126
|
|
I have a JButton, and have attached a mouse listener to detect the mouse presses. I try to disable this button by the setEnabled() method, which does color the button differently, but does not prevent the Action from performing when the button is pressed. Is there any way to disable the action attached to this button instead of adding and removing listeners on a per-click basis? Zak
|
 |
Rachel Swailes
Ranch Hand
Joined: May 18, 2004
Posts: 434
|
|
What about in the actionPerformed, doing a check to see if the button is enabled or not and based on this you can continue with the action or just return out of the actionPerformed eg. public void actionPerformed(ActionEvent ae){ boolean enabled = myButton.isEnabled(); if(enabled == false) return; } Cheers, rachel
|
 |
Zak Nixon
Ranch Hand
Joined: Sep 27, 2003
Posts: 126
|
|
But this is only for action listeners, but what about mouse listeners attached to a JButton? Zak
|
 |
Rachel Swailes
Ranch Hand
Joined: May 18, 2004
Posts: 434
|
|
It's a bizarre problem, because when I use setEnabled, it swiches the action listeners off as expected. Could you post some code? Cheers, Rachel
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Zak Nixon: But this is only for action listeners, but what about mouse listeners attached to a JButton?
Why do you attach one? I never found the need to do so.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: JButton disabling mouse listeners
|
|
|