More on Groups and Shadows

This is a continuation of the groups and shadows discussion.

Groups

The primary purpose of GUI builder is to help you create groups. To be considered a group, a class must be a subclass of the Group class.

Rules for Writing a Group

Shadows

To import a custom AWT component into the GUI builder's palette, you must write a shadow class for it. GUI builder includes shadow classes for all the standard AWT components.

Rules for Writing a Shadow

Both shadows and groups can be imported into the palette of GUI builder. For information on how this can be done, see Accessing AWT Methods for Shadows Classes.

Putting AWT Components That Do Not Have a Shadow Inside a Group

If an AWT component does not have a shadow, add it as a child of an existing panel or frame that is already inside the group. The events from the AWT component will be delivered to the group. The message target will be the same as the AWT event target. Normally the message target is set to the shadow corresponding to the AWT event target, but in this case there is no corresponding shadow.

Another method for adding an AWT component is to use the Generic Component. The Generic Component is a special component that you can use to import any custom AWT component class that you write. See Adding Custom Components and Windows for a discussion of Generic Component.

How to Use Groups Without the Generated Main

The following examples show how to use groups without the generated main.

Main

  // Construct the group

  Group group = new MyFancyGroup();

  // Set the group environment.  The "args" are command 
  // line arguments.

  group.setEnvironmentInfo(null, args);

  // Initialize the group

  group.initialize();

  // Set the top level on the group

  WindowShadow win = (WindowShadow)group.getWindow();
  if (win instanceof FrameShadow) {
    win.createBody();
    group.setTopLevel((Frame)win.getBody());
  }
  else {
    group.setTopLevel(/* Pass in an existing frame window
			 from your application */);
  }

  // Create the group

  group.create();

  // If the group is a panel group, add it in the 
  // hierarchy somewhere

  if (group.getPanel() != null) {
    myApplicationFrame.add((Panel)group.getPanel().getBody());
  }

  // Start the group

  group.start();

Applet

  // Construct the group

  Group group = new MyFancyGroup();

  // Set the group environment.  The "applet" must be available here.

  group.setEnvironmentInfo(myApplet, null);

  // Initialize the group

  group.initialize();

  // Set the top level on the group

  WindowShadow win = (WindowShadow)group.getWindow();
  if (win instanceof FrameShadow) {
    win.createBody();
    group.setTopLevel((Frame)win.getBody());
  }
  else {
    // Figure out the applet's frame

    Component comp = applet;
    while (comp != null && !(comp instanceof Frame))
      comp = comp.getParent();
    group.setTopLevel((Frame)comp);
  }

  // Create the group

  group.create();

  // If the group is a panel group, add it in the 
  // hierarchy somewhere

  if (group.getPanel() != null) {
    myApplet.add((Panel)group.getPanel().getBody());
  }

The start, stop, and destroy methods should be forwarded from the applet to the group:

  group.start();
  group.stop();
  group.destroy();

See also:

What Are Groups and Shadows?
Generating Java Source Code
Adding Operations to Components
GUI Builder Runtime Classes
Adding Operations to Menus
Importing Components

Visual Java API Documentation
Visual Java GUI Builder Runtime Packages
Class Hierarchy
Index of All Fields and Methods