Visual Inheritance Problem

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Visual Inheritance Problem

Postby jamiedougal » Thu Dec 06, 2007 10:56 am


I have been trying to get Visual Inheritance working correctly, and am almost there. The last problem that i am trying to get around, is that in the designer, in the subclass, i can't seem to manipulate any of the widgets that were created in the super class. They can be manipulated in the code, and the window will render them correctly.

The bigger problem with this is that if there is a composite of some kind defined in the super class, controls can't be added to it in the subclass. I can add the control in the code by hand, and it runs correctly, however the designer won't render the control at all.

i have included the code samples:
Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

public class Shell1 extends Shell {
   protected Group mainFormGroup;
   public Shell1(Display display, int style) {
      super(display, style);
      setLayout(new FormLayout());
      setText("SWT Application");
      setSize(492, 341);

        mainFormGroup = new Group(this, SWT.NONE);
        final FormData fd_mainFormGroup = new FormData();
        fd_mainFormGroup.left = new FormAttachment(0, 5);
        fd_mainFormGroup.bottom = new FormAttachment(0, 336);
        fd_mainFormGroup.right = new FormAttachment(0, 389);
        mainFormGroup.setLayout(new FormLayout());

      Group group;
      group = new Group(this, SWT.NONE);
      group.setLayout(new FormLayout()); = new FormAttachment(group, 0, SWT.TOP);
      final FormData fd_group = new FormData();
      fd_group.right = new FormAttachment(0, 485);
      fd_group.bottom = new FormAttachment(0, 336); = new FormAttachment(0, 13);
      fd_group.left = new FormAttachment(0, 395);

      final Button okButton = new Button(group, SWT.NONE);
      final FormData fd_okButton = new FormData();
      fd_okButton.bottom = new FormAttachment(0, 37); = new FormAttachment(0, 8);
      fd_okButton.right = new FormAttachment(0, 77);
      fd_okButton.left = new FormAttachment(0, 8);

      final Button cancelButton = new Button(group, SWT.NONE);
      final FormData fd_cancelButton = new FormData();
      fd_cancelButton.bottom = new FormAttachment(0, 72); = new FormAttachment(0, 43);
      fd_cancelButton.right = new FormAttachment(0, 77);
      fd_cancelButton.left = new FormAttachment(0, 8);
   protected void checkSubclass() {
      // Disable the check that prevents subclassing of SWT components

and the subclass
Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;

public class Shell2 extends Shell1 {

   public static void main(String args[]) {
      try {
         Display display = Display.getDefault();
         Shell2 shell = new Shell2(display, SWT.SHELL_TRIM);;
         while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
      } catch (Exception e) {
   public Shell2(Display display, int style) {

      super(display, style);
      setText("SWT Application - Shell2");
      setSize(492, 341);
      Button button = new Button(mainFormGroup, SWT.NONE);
      button.setText("Test Button");

Any help is appreciated,
Posts: 1
Joined: Thu Dec 06, 2007 10:35 am

Re: Visual Inheritance Problem

Postby Eric Clayberg » Fri Dec 07, 2007 10:50 pm

See the Visual Inheritance docs and flash demo.

In order to reference a widget in a subclass, it must be exposed as a public component in the superclass via an accessor.
Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests