Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- From: "TimOnGoogle" <fromGoogle@xxxxxxxxxxx>
- Date: 27 Sep 2005 16:39:47 -0700
Hi Roedy...
Well, I ended up doing as you suggested, creating my own JButton and
JMenuItem subclasses, and adding to my Action, like so (the null check
was required, because the superconstructor calls getText(), and the
instanceof is done in case some dummy decides to use an Action
implementation that is not MyAction):
public MyAction extends AbstractAction {
...
public MyAction(String buttonText, String menuText) {
this.setButtonText(buttonText);
this.setMenuText(menuText);
}
...
}
public MyButton extends JButton {
public MyButton(MyAction action) {
super(action);
}
public String getText() {
Action action = this.getAction();
if ((action == null) || !(action instanceof MyAction)) {
return super.getText();
}
return ((MyAction) action).getButtonText();
}
}
.
- Follow-Ups:
- Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- From: Babu Kalakrishnan
- Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- From: TimOnGoogle
- Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- References:
- Can I use an Action, but have diff text for JButton versus JMenuItem?
- From: TimOnGoogle
- Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- From: Roedy Green
- Can I use an Action, but have diff text for JButton versus JMenuItem?
- Prev by Date: Re: Help: How to use JWindow as Popup
- Next by Date: Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- Previous by thread: Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- Next by thread: Re: Can I use an Action, but have diff text for JButton versus JMenuItem?
- Index(es):