NullPointerException when adding a custom control

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

NullPointerException when adding a custom control

Postby Paul.Helster » Mon Apr 18, 2005 5:50 am

I get a NullPointerException when adding a custom control. Here is how to reproduce it on Eclipse 3.0.1, and SWT-Designer Trial 4.0.0.

1- Using the designer, I created the custom composite that I included in this message.

2- I managed to have this composite to be offered as a Custom Control.

3- I created a new SWT Composite in the designer.

4- I tried to put the composite from #1 into the new composite. Nothing gets added and the log shows this:

Code: Select all
   at com.swtdesigner.model.swt.forms.control.FormsLabelInfo.createSingleControl(
   at com.swtdesigner.model.swt.widgets.control.ControlInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.ThisCompositeInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.FrameInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.ThisCompositeInfo.createControl(
   at com.swtdesigner.model.swt.widgets.composite.AbstractCompositeInfo.createControl(
   at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(
   at com.swtdesigner.model.swt.widgets.control.ControlInfo.notifyPropertyChanged(
   at com.swtdesigner.model.JavaInfo.notifyPropertyChanged(
   at com.swtdesigner.model.JavaInfo.unlockNotify(
   at com.swtdesigner.model.JavaInfo.endEdit(
   at com.swtdesigner.gef.command.swt.layout.absolute.AbsoluteAddControlCommand.execute(
   at org.eclipse.gef.commands.CommandStack.execute(
   at com.swtdesigner.gef.DesignerEditDomain$1.execute(
   at org.eclipse.gef.EditDomain.mouseUp(
   at com.swtdesigner.gef.DesignerEditDomain.mouseUp(
   at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(
   at org.eclipse.swt.widgets.TypedListener.handleEvent(
   at org.eclipse.swt.widgets.EventTable.sendEvent(
   at org.eclipse.swt.widgets.Widget.sendEvent(
   at org.eclipse.swt.widgets.Display.runDeferredEvents(
   at org.eclipse.swt.widgets.Display.readAndDispatch(
   at org.eclipse.ui.internal.Workbench.runEventLoop(
   at org.eclipse.ui.internal.Workbench.runUI(
   at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(
   at org.eclipse.ui.PlatformUI.createAndRunWorkbench(
   at org.eclipse.core.internal.runtime.PlatformActivator$
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.core.launcher.Main.basicRun(
   at org.eclipse.core.launcher.Main.main(

Following is the code of the Composite that was added as a Custom composite.

Code: Select all
package examples.forms;

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.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class WindControl extends Composite {

  public WindControl(Composite parent, int style) {
    super(parent, style);
    final FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 5;
    formLayout.marginHeight = 5;
    FormToolkit toolkit = new FormToolkit(Display.getCurrent());

    final Label nLabel = toolkit.createLabel(this, "N", SWT.NONE);
    final FormData formData_2 = new FormData();
    formData_2.bottom = new FormAttachment(0, 23); = new FormAttachment(0, 6);
    formData_2.left = new FormAttachment(0, 59);

    final Label eLabel = toolkit.createLabel(this, "E", SWT.NONE);
    final FormData formData = new FormData(); = new FormAttachment(0, 52);
    formData.left = new FormAttachment(0, 109);
    formData.bottom = new FormAttachment(0, 69);
    formData.right = new FormAttachment(0, 117);

    final Label wLabel = toolkit.createLabel(this, "W", SWT.NONE);
    final FormData formData_3 = new FormData(); = new FormAttachment(0, 54);
    formData_3.left = new FormAttachment(0, 7);

    final Label sLabel = toolkit.createLabel(this, "S", SWT.NONE);
    final FormData formData_1 = new FormData(); = new FormAttachment(0, 106);
    formData_1.left = new FormAttachment(0, 59);
    formData_1.bottom = new FormAttachment(0, 123);

    final Button button = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_4 = new FormData();
    formData_4.left = new FormAttachment(0, 55);
    formData_4.bottom = new FormAttachment(0, 44); = new FormAttachment(0, 25);

    final Button neButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_5 = new FormData();
    formData_5.left = new FormAttachment(0, 77);
    formData_5.right = new FormAttachment(0, 93); = new FormAttachment(0, 32);

    final Button eButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_6 = new FormData(); = new FormAttachment(0, 52);
    formData_6.left = new FormAttachment(0, 88);
    formData_6.bottom = new FormAttachment(0, 70);
    formData_6.right = new FormAttachment(0, 104);

    final Button seButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_7 = new FormData(); = new FormAttachment(0, 74);
    formData_7.left = new FormAttachment(0, 77);
    formData_7.bottom = new FormAttachment(0, 93);

    final Button button_4 = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_8 = new FormData(); = new FormAttachment(0, 85);
    formData_8.left = new FormAttachment(0, 55);
    formData_8.bottom = new FormAttachment(0, 104);

    final Button swButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_9 = new FormData();
    formData_9.right = new FormAttachment(button_4, -5, SWT.LEFT);
    formData_9.bottom = new FormAttachment(seButton, 0, SWT.BOTTOM);
    formData_9.left = new FormAttachment(button_4, -21, SWT.LEFT);

    final Button wButton = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_10 = new FormData(); = new FormAttachment(0, 54);
    formData_10.left = new FormAttachment(0, 24);
    formData_10.bottom = new FormAttachment(0, 73);

    final Button button_7 = toolkit.createButton(this, "", SWT.RADIO);
    final FormData formData_11 = new FormData(); = new FormAttachment(neButton, 0, SWT.TOP);
    formData_11.left = new FormAttachment(swButton, 0, SWT.LEFT);

  public void dispose() {

  protected void checkSubclass() {
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

This is a FormToolkit problem

Postby Paul.Helster » Mon Apr 18, 2005 5:31 pm

I created other custom composites. Whenever I try to import them in another composite, I get the same NullPointerException.

These composite are Form based (i.e. their embedded controls are created using the toolkit).

The exception only occurs when a toolkit is used to create the controls embedded in the custom composite that I am trying to add to another composite. If I replace the toolkit.createXXX() with new XXX(), it works fine.

This sounds so easy to reproduce that it looks like I am doing something wrong (i.e. I cannot believe I would be the first one identifying this bug).

Any idea?

Eclipse 3.0.1
SWT-Designer 4.0.0 trial

Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Re: NullPointerException when adding a custom control

Postby Eric Clayberg » Mon Apr 18, 2005 6:28 pm

Paul.Helster wrote:I get a NullPointerException when adding a custom control.

The latest v4.0.1 build corrects the problem.
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

Postby Paul.Helster » Mon Apr 18, 2005 7:04 pm

Yes it does fix the problem. Thank you. And I am now a registered user :)
Posts: 31
Joined: Fri Apr 15, 2005 6:03 am

Postby Eric Clayberg » Mon Apr 18, 2005 7:19 pm

Paul.Helster wrote:Yes it does fix the problem. Thank you. And I am now a registered user :)

Thank you! :-)
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 1 guest