We make multiple buttons, e.g. [Joe], [Mary], [Paul], [Suzy], etc. And
when we set a same Action object to these buttons, button texts "Joe",
"Mary", etc. are all disappeared from the buttons' surfaces. This text
disappearing phenomenon occurs when we use only one button. It should
be needless to say that if we give a string to the Action's
constructor, all the buttons' got the same text string. That isn't
what we want. Action is a much handier object than Listener in Swing
framework, so we like to stick to using them. How could we solve this
problem?
Todd Corley - 05 Jan 2004 16:50 GMT
You have a major misconception on usage of Action.
One of the more common usage of Action is to share information
between a menu item and a tool bar button. The Action allows
sharing resources (text, icon) and state in a single object that
can be used in multiple locations.
If you want to have different buttons perform the same action, just
create an action listener and add it to all the desired buttons.
Hope this helped,
Todd
Jon A. Cruz - 05 Jan 2004 19:23 GMT
> It should
> be needless to say that if we give a string to the Action's
> constructor, all the buttons' got the same text string. That isn't
> what we want. Action is a much handier object than Listener in Swing
> framework, so we like to stick to using them. How could we solve this
> problem?
It could be more appropriate to use multiple Actions.
Or just change the text on the object after you create a JButton on
using that action.
hiwa - 06 Jan 2004 02:27 GMT
Thanks Todd and Jon.
Yes. It was my misconception about Action's functionality!