How to add Swing component to SWT?

不想你离开。 提交于 2019-12-10 13:25:46

问题


I want to add a Swing component (JTree) to my code which employs SWT.
Is there any way by which we can accomplish this?
I know that we have TreeViewer component in SWT/Jface, but i have got an already developed Jtree implemenatation and would like to add that, instead of rewriting using TreeViewer.


回答1:


You can use the SWT/AWT Bridge.

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

The SWT_AWT.newFrame(Compisite) method will return a java.awt.Frame. Since a Frame is a Container you can add any Component. Thus also a swing component.




回答2:


The http://wiki.eclipse.org/Albireo_Project might help:

"The Albireo project builds on the SWT_AWT bridge to provide more complete Swing/SWT integration, resulting in a better "out-of-the-box" experience and more credibility for the entire notion of Swing/SWT integration."

Extend the SwingControl and implement createSwingComponent() and getLayoutAncestor(). http://eclipsesrc.appspot.com/jsrcs/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/SwingControl.java.html



来源:https://stackoverflow.com/questions/20905989/how-to-add-swing-component-to-swt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!