Extreme Java When vanilla Java is not enough

10Jun/080

Adding special chars to NetBeans action name

This one I posted in NetBeans mailing lists. If you want to show a special char (like a slash - "/") in the action display name (i.e. in the way your user will see it), the right way is to pass it to the AbstractAction constructor (just like the templates of NetBeans):

public class SpecialCopyPasteAction extends AbstractAction {
 
  public SpecialCopyPasteAction() {
    super(NbBundle.getMessage(SpecialCopyPasteAction.class,
        "CTL_SpecialCopyPasteAction"));
  }
 
  public void actionPerformed(ActionEvent evt) {
    // TODO: Implement it
  }
}

And, in Bundle.properties:

CTL_SpecialCopyPasteAction=Special Copy/Paste

Remember that the action name in layer.xml is mapped to a system file name. You cannot put a "/" on file names, even on Windows. This is one of the reasons NB filesystem has the localization feature.