简体   繁体   English

将Swing组件添加到Eclipse RCP插件

[英]Adding Swing components to Eclipse RCP plugin

I'm having trouble embedding Swing components inside SWT (such as eclipse plugin..) Currently what I have: 我在SWT中嵌入Swing组件时遇到了麻烦(比如eclipse插件..)目前我所拥有的:

 public void createPartControl(Composite parent) {
  java.awt.Frame f = SWT_AWT.new_Frame(parent);
  JPanel panel = new JPanel(new BorderLayout());
  JButton button = new JButton("Swing button");
  JLabel label = new JLabel("Swing label");
  panel.add(label,BorderLayout.NORTH);
  panel.add(button,BorderLayout.CENTER);
  f.add(panel);
 }

This code snippet fails to load, the plugin crashes on the first line... 此代码段无法加载,插件在第一行崩溃...

Any idea how to incorporate these components? 知道如何合并这些组件吗?

Thanks! 谢谢!

http://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html http://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html

Minimally, embedding an AWT frame inside an SWT composite is just two simple lines of code 最低限度,在SWT组合内嵌入AWT帧只需两行简单的代码

Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(composite);

Since your code is failing at the first line then please first make sure that the parent Composite is created using SWT.EMBEDDED . 由于您的代码在第一行失败,请首先确保使用SWT.EMBEDDED创建父Composite If it is not then create a child composite using the SWT.EMBEDDED and then call 如果不是,则使用SWT.EMBEDDED创建子组合,然后调用

java.awt.Frame f = SWT_AWT.new_Frame(newChildComposite);

An instance of org.eclipse.swt.Composite is created with the SWT.EMBEDDED style. 使用SWT.EMBEDDED样式创建org.eclipse.swt.Composite的实例。 This style signals that an AWT frame is to be embedded inside the Composite. 此样式表示AWT帧将嵌入Composite内部。 The call to the static new_Frame method creates and returns such a frame. 对静态new_Frame方法的调用会创建并返回这样的帧。 The frame may then be populated with AWT and/or Swing components. 然后可以用AWT和/或Swing组件填充该帧。

Taken from Article-Swing-SWT-Integration 取自Article-Swing-SWT-Integration

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

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