Java – add swing components to the eclipse RCP plug-in

I encountered a problem embedding swing components in SWT (e.g. Eclipse Plug-in..)

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 snippet could not be loaded, the plug-in crashed on the first line

Do you know how to merge these components?

thank you!

Solution

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

At a minimum, embedding AWT frames in SWT combinations requires only two lines of simple code

Composite composite = new Composite(parent,SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(composite);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>