• Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton disabling mouse listeners

 
Zak Nixon
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this is only for action listeners,
but what about mouse listeners attached to a JButton?

Zak
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!