开发者

Add an SWT widget to a swing JPanel

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, whic开发者_如何学Goh 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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜