Re: Can I use an Action, but have diff text for JButton versus JMenuItem?



On 26 Sep 2005 15:26:04 -0700, "TimOnGoogle" <fromGoogle@xxxxxxxxxxx>
wrote or quoted :

>I want to use an AbstractAction as the basis for some Action classes in
>a Swing app, but I want the text of the action's name to be different
>for JButtons than it is for JMenuItems.
>
>Is there any way to do this, or do I need to have two separate Action
>instances to do this?

You pass your action to the JButton constructor. It then asks for the
value associated with the text key to get the text for the button.
Ditto the JMenuItem.

To change that behaviour your would need to subclass JButton say to
use the "buttonText" key instead.

The method that handles that is AbstractButton.
configurePropertiesFromAction(Action a, String[] types)
Which is package scope. I think you are getting into a can of worms.

What might be easier is to encode both names in the Action, say
separated by |, then invoke some code to grab which one you really
wanted after setAction has completed.

What is probably even easier, especially considering those who come
after you is two Actions or no Actions.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
.