GUI Commands User GuideVersion 2.1 |
||
Programmatic ConfigurationMost of the time GUI Commands will automatically configure your commands based on their id. Occassionally you need to create commands programmatically without any configuration. In this case you can use anonymous commands. Anonymous CommandsAnonymous commands are the same as normal commands except that they are created without an id. This is achieved by using the no-arg constructor. Anonymous commands do have two restrictions however, they are as follows:
The following shows an example of creating an anonymous command and configuring its default face. // create an anonymous command using the no-arg constructor ActionCommand myCommand = new ActionCommand() { public void handleExecute() { Toolkit.getDefaultToolkit().beep(); } } // and programmatically configure its face myCommand.getDefaultFace(true).setText("My Command"); This command can only be added to a group using either a Group Builders or Expansion Points. See Using Faces Programmatically for more information on creating faces. Creating Commands with no ConfigurationIn cases where you need an Id but don't want to specify or load any configuration you can
override the The following example shows a command with the id // create a command with an id but no configuration. ActionCommand noConfig = new ActionCommand("my-command") { @Override protected void loadConfiguration() { // don't try and load any configuration. } public void handleExecute() { Toolkit.getDefaultToolkit().beep(); } } // programmatically configure its face noConfig.getDefaultFace(true).setText("My Command"); |
||