简体   繁体   English

将SWT小部件添加到swing JPanel

[英]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. 我有一个SWT Button,并且想要仅使用Button来覆盖现有JPanel的内容。 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. 我当前的策略是将SWT Button作为初始的null字段,然后通过一种方法进行设置,该方法将使用SWT Button刷新JPanel。

Button ibutton = null;

The following is taken from my constructor (class extends JPanel ): 以下内容来自我的构造函数(类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: 需要注意以下几点,因为您似乎不熟悉SWT_AWT桥:

  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. 并行线程应该正在从显示读取和调度事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM