Pergunta

Here on Stack Overflow I read a lot about using Swing Actions rather than ActionListeners, so I started to use them within the application's menu.

Everything worked out nice until I introduces I18N, only to find out that the actionCommand of the MenuItem changes accordingly to the language.

Here is what I do:

class ExitAction extends AbstractAction {
    public void init() {
        putValue(Action.NAME, messageSource.getMessage("app.gui.action.exitApplication"));
    }
}

My guess is, that I did understand something wrong and this is not the way to do what I want to do.

Can you please help me?

Foi útil?

Solução

Two things...

Firstly, NAME affects the text of button, but if not specified, will also set the actionCommand. Property. Instead I think you're after the ACTION_COMMAND_KEY property

Secondly, there should actually be little need for it, as the Action is self contained, hat is, it is it's own ActionListener, so when actionPerformed is called on your Action, you are guaranteed the association

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top