Creating Faces Programmatically

Commands and groups define various methods for retrieving and creating faces. The following summarises:

MethodDescription
getDefaultFace() Gets the default face. Returns null if not defined.
getDefaultFace(boolean create) Gets the default face, optionally creating it if not defined.
getFace(String context) Gets the face for the specified context. Returns null if not defined.
getFace(String context, boolean create) Gets the face for the specified context, optionally creating it if not defined.
findBestFace(String context) Finds the best face for the specified context. Throws a FaceNotFoundException if no face was found.

The following is an example of creating an anonymous command and programmatically setting the properties of the default face:

   // Create an anonymous command...
   ActionCommand command = new ActionCommand()
   {
      public void handleExecute()
      {
         Toolkit.getDefaultToolkit().beep();
      }
   }

   // get the default face, creating it as required.
   Face defaultFace = command.getDefaultFace(true);
   defaultFace.setText("Press _Me");
   defaultFace.setAccelerator(KeyStroke.getKeyStroke("control P"));

   // get the toolbar face, creating it as required.
   Face toolbarFace = command.getFace(Face.TOOLBAR, true);
   toolbarFace.setExtendsContext(Face.DEFAULT);
   toolbarFace.setIcon(icon);