javajlabelevent-dispatch-thread

JButton: actionPerformed while invisible/disabled?


Is it possible that, for example, a JButton calls actionPerformed() of an ActionListener attached to it while the button itself is hidden or has been disabled?

Like, the user clicks the button, an event gets added to the Event Queue, and in a previous event the button gets disabled.

I'd think that this would not lead to an actionPerformed(), because the user merely submitted a click- or press-event that checks all this stuff in the current JFrame.

But does anybody know if there is any case where such an unwanted situation happens? Of course, always provided that you don't do anything with Swing objects outside of the EDT.

Edit for anyone looking at this: Yes, it can indeed happen under certain circumstances. I should post an example as an answer at some point.


Solution

  • From the JavaDocs

    public void setEnabled(boolean enabled)

    Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input.

    For more info

    http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#setEnabled%28boolean%29

    INFO : JButton extends AbstractButton which extends JComponent