Set JButton so that it cannot be pressed or to temporary disable actionListener?

Is it possible or do I have to remove and than add them actionListener again You can add a boolean variable in the action listener like this: boolean ignoreEvents = false and then wrap your action-code in if (ignoreEvents) return; ignoreEvents = true; // your code here... ignoreEvents = false Just make sure the code is properly synchronized From a user-interface perspective, you might be better of disabling the buttons instead.

Is it possible or do I have to remove and than add them actionListener again. You can add a boolean variable in the action listener like this: boolean ignoreEvents = false; and then wrap your action-code in if (ignoreEvents) return; ignoreEvents = true; // your code here... ignoreEvents = false; Just make sure the code is properly synchronized. From a user-interface perspective, you might be better of disabling the buttons instead.

JButton button = new JButton("hello"); button. SetEnabled(false) That will disable the button, if needed.

Besides disabling GUI elements themselves, you might construct them using the Action (or AbstractAction) class and disable/enable the action instead. Whatever UI elements were formed from the action will be disabled/enabled accordingly.

I have actionListener on JButtons and if I press one of them, I want to somehow disable actionlistener on other ones without removing it. Is it possible or do I have to remove and than add them actionListener again. I forgot to mention, that I set "button.

SetPressedIcon(icon)" and I don't want to show this icon. So the mentioned soulution - button. SetEnabled(false) won't work.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions