【问题标题】:Add an SWT widget to a swing JPanel将 SWT 小部件添加到 swing JPanel
【发布时间】:2009-11-08 20:58:35
【问题描述】:

我知道这可能是不可能的,但我很想知道是否有人已经完成了这项工作,或者有解决方法。

我有一个 SWT 按钮,我想覆盖现有的 JPanel 的内容,只存在该按钮。我目前的策略是将 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.

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

【问题讨论】:

标签: java jpanel swt button swing


【解决方案1】:

你必须这样做:

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

【讨论】:

  • 请您详细说明 1 和 2,因为我对此有例外?
猜你喜欢
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-14
  • 2016-10-25
  • 2016-03-12
相关资源
最近更新 更多