Do not mix program logic and user interface texts. An action command is a property other than the displayed text, and only the displayed text is displayed by default if it is not explicitly specified.
public abstract class IconNames { public static final String ButtonFett_CMD = "DO-BOLD"; public static final String ButtonFett_TXT = java.util.ResourceBundle.getBundle("recources/buttonproperties").getString("fett"); }
...
JButton b=new JButton(IconNames.ButtonFett_TXT); b.setActionCommand(IconNames.ButtonFett_CMD);
...
String buttonText = e.getActionCommand(); switch(buttonText) { case IconNames.ButtonFett_CMD:
This works for subclasses of AbstractButton that also contain menu items. If you are dealing with Action implementations directly (which I doubt you see the switch statement), you must distinguish between the properties Action.NAME and Action.ACTION_COMMAND_KEY .
source share