Beware of disabled Action  
Author Message
Arnaud Berger





PostPosted: 2003-9-1 20:47:00 Top

java-programmer, Beware of disabled Action Hi !

just a note to warn you about some javax.swing.AbstractAction problem

My GUI dispays a JButton.
depending on the user's state, I do a setAction(AAction)
or a setAction(BAction).

AAction and BAction each extend AbstractAction and possess their own icon
(ImageIcon).

Here is a sample scenario :

1) button.setAction(AAction)
2) AAction.setEnabled(false)
3) button.setAction(BAction)
4) BAction.setEnabled(false)

the result of this is : the Action linked to the button is BAction as
expected, and the icon is...AAction's disabled icon (original icon greyed).

The only workaround I've found is to do button.setDisabledIcon(null) before
any new setAction()

It seems that an AbstractAction doesn't possess a disabled icon on its own,
and relies on the JComponent's one.
The first time, 1) and 2) have the consequence of creating a disabled icon
for my button , which doesn't have any at the beginning.
Then, 3) and 4) won't change this disabled icon, because the button now has
one

Regards,

Arnaud