Creating a new Java visual class

You can use the New Java Visual Class wizard to quickly create a visual class that you can then design within the visual editor.

Before you can create a new Java visual class, you must create a Java project or Plug-in project where you can place the visual class. A Plug-in project that is enabled for Rich Client Platform (RCP) application development is required if you want to create a new RCP view or editor.

The wizard generates new visual classes based on a few quick selections. For example, you can specify the toolkit or style that you want to use (RCP, SWT, Swing, AWT, or Other), the initial container or composite that you want the visual class to instantiate (for example, an RCP view, an SWT composite, or a Swing JFrame), and whether you want the visual class to be an application that includes a public static void main(String[] args) method.

Tip: If you select the Swing Application style, the wizard generates a Swing application that includes commonly used menus and event handlers already built into it.

To create a new Java visual class for use in the visual editor for Java:

  1. In the Java perspective, click File > New > Visual Class. The New Java Visual Class wizard opens.
    New Java Visual Class dialog
  2. In the Source Folder field, enter the workspace folder where the class will be saved. This will default to your current project.
  3. In the Package field, enter the name of the Java package where you want the visual Java class to be packaged. Tip: If you open the wizard from the pop-up menu of the package, this field defaults to that package name.
  4. Ensure that the Enclosing type check box is cleared. Selecting this option creates an inner class in another class that you specify, so no new visual class is created.
  5. In the Name field, enter the name for the new Java visual class.
  6. Select one of the following modifiers to specify access control for the class:
    • public - makes the class completely available to any other class that wants to use it
    • default - sets no modifier, making it available to any other class in the same package
  7. Optional: Select one of the following modifiers for the class:
    • abstract - indicates that the class will serve in a superclass role
    • final - indicates that the class cannot be subclassed
  8. In the Style list, select the toolkit and visual element that you want your new visual class to extend. For example, you can select RCP view, SWT composite, or Swing JPanel.
    Note: An RCP view or editor can only be created in a Plug-in project that is enabled for Rich Client Platform (RCP) application development
    The Superclass field displays the appropriate class name. If you select Other as the style, you need to specify the superclass that you want to extend or accept the default java.lang.Object. The java.lang.Object superclass can be used, for example, for a SWT application that uses a SWT Shell.
  9. Optional: To import and implement an additional interface in your new visual class, click Add and select the interface, then click OK. The interfaces to be implemented are listed in the Interfaces field. Repeat this step for each interface.
  10. Optional: Select any of the following check boxes to generate additional method stubs in your new visual class:
    • public static void main(String[] args) - generates a stub main() method for running the class as a Java application. For SWT applications, the visual editor also generates the necessary display loop in the main method.
    • Constructors from superclass - generates constructor stubs to initialize methods inherited from the superclass.
    • Inherited abstract methods - generates stubs for additional abstract methods inherited from the superclass.
  11. Select Generate comments if you want the wizard to add comments to the source code, as configured in the project properties.
  12. Click Finish.
The wizard generates a new .java file that includes the new visual class, and the class opens in the visual editor for Java
Related tasks
Creating an RCP editor in the visual editor
Creating an RCP view in the visual editor

(C) Copyright IBM Corporation 1999, 2004. All Rights Reserved.