The problem with this
new approach is that getActionCommand() now does return the correct
value but in javax.swing.DefaultButtonModel.setPressed() an ActionEvent
gets fired with only the actionCommand set (which may be null) without
asking the label. Any idea about that?
Yes this is the intended behavior.
To elaborate this a bit:
Create a JButton and its model like this: new JButton("foo").
Asking the JButton for its actioncommand will return "foo" (no real ac
set -> returns the label instead).
However if you retrieve the model and ask it instead it will return
null. The same goes with actionevents: If an actionevent is created from
within the buttonmodel then it will show null as its actioncommand.
Now I our buttons register themselves as ActionListener of their model.
A few days ago this ActionListener's actionPerformed implementation
simply changed the source of the ActionEvent from the model to the
button and dispatched the actionevent to the button's own
actionlisteners. This was troublesome because the ActionEvent's
actionCommand was set by the model (usually to null) and could not be
changed (there is no setter and the class' field is final). I found out
that the JDK does not work this way* and my fix was to simply create a
new ActionEvent for the button's actionlisteners which uses most of the
ActionEvent provided by the model.
I hope this makes sense.