views:

185

answers:

1

I understand that this may be impossible, but I would sure like to know if somebody has accomplished this, or have a work-around.

I have an SWT Button and am wanting to overwrite an existing JPanel's contents with just the Button being present. My current strategy is to have the SWT Button as an initial null field and then set it through a method, which will refresh the JPanel with the SWT Button.

Button ibutton = null;

The following is taken from my constructor (class extends JPanel):

ibutton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
 switch (e.type) {
 case SWT.Selection:
 }
}


  });

add(ibutton); //add is the usual swing assignment function
                          //  and thus does not work.

If there is another means to acheive this, I would be more than grateful to hear what you have.

+2  A: 

You have to do something like this:

Canvas canv = new Canvas();
add(canv);//add to ur parent container
Shell shell = SWT_AWT.new_Shell(display, canv);
shell.add(ibutton);

There are following points to be noted, since you seem to be new to the SWT_AWT bridge:

  1. The parent should have been displayed(peer should be created) by the time the above code is called.
  2. A parallel thread should be reading and dispatching events from the display.
Suraj Chandran