0

我知道这可能是不可能的,但我很想知道是否有人已经做到了这一点,或者有解决方法。

我有一个 SWT 按钮,我想覆盖现有的 JPanel 的内容,只存在 Button。我当前的策略是将 SWT Button 作为初始 null 字段,然后通过一个方法设置它,该方法将使用 SWT Button 刷新 JPanel。

Button ibutton = null;

以下内容取自我的构造函数(类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.

如果有其他方法可以实现这一点,我将非常感激听到您的消息。

4

1 回答 1

3

你必须做这样的事情:

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

由于您似乎是 SWT_AWT 桥的新手,因此需要注意以下几点:

  1. 在调用上述代码时,父级应该已经显示(应该创建对等点)。
  2. 并行线程应该从显示器读取和调度事件。
于 2009-11-10T04:11:30.893 回答