2

我想使用 swt 来制作 GUI,但我不想使用 eclipse 来编程。有没有办法做到这一点。此外,是否有任何不是 Eclipse 插件的 swt GUI 设计器。

4

3 回答 3

5

当然可以独立于 Eclipse-RCP 平台使用 SWT。你只需要有合适的罐子。查看这些示例http://www.eclipse.org/swt/snippets/。例如:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet169 {
public static void main (String [] args) {
    Display display = new Display ();
    final Shell shell = new Shell (display);
    shell.setLayout (new FillLayout ());
    Listener listener = new Listener () {
        public void handleEvent (Event e) {
            Control [] children = shell.getChildren ();
            for (int i=0; i<children.length; i++) {
                Control child = children [i];
                if (e.widget != child && child instanceof Button && (child.getStyle () & SWT.TOGGLE) != 0) {
                    ((Button) child).setSelection (false);
                }
            }
            ((Button) e.widget).setSelection (true);
        }
    };
    for (int i=0; i<20; i++) {
        Button button = new Button (shell, SWT.TOGGLE);
        button.setText ("B" + i);
        button.addListener (SWT.Selection, listener);
        if (i == 0) button.setSelection (true);
    }
    shell.pack ();
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
}

此外,SWT 设计人员不受 Eclipse 插件的约束,只需 google 即可找到合适的插件。Eclipse 的 SWT 设计器示例(但不仅适用于 Eclipse 插件): http: //www.eclipse.org/windowbuilder/

于 2012-09-18T13:43:36.970 回答
0

SWT 独立于 Eclipse。您可以将它用于基于 RCP/SWT 的应用程序,也可以用作基于 J2SE/SWT 的应用程序。在第一种情况下,您将使用它与 Eclipse Equinox OSGi 并添加对 org.eclipse.ui*... 的依赖项,在第二种情况下,您需要下载特定于平台的 SWT*.jar 库并将其放入 J2SE 应用程序的类路径中。

我现在更喜欢 RCP/SWT 开发,因为它更可插件化和模块化,就像 J2SE 的使用一样。

我更喜欢 Eclipse IDE 而不是其他 IDE,因为我只是从 Eclipse 开始(即使我也尝试过 Netbeans 或 InteliJ)——但这是每个开发人员选择使用哪个 IDE 的问题。

在玩了一些 SWT 和 JFace 之后,即使没有 WindowBuilder,您也可以轻松创建 GUI -> 我确实使用 WindowBuilder,但是在生成代码后,我总是自己更改代码,但它当然是个好工具。

于 2013-07-25T20:19:55.253 回答
0

您必须将 Eclipse 安装到您的计算机上,但是您可以将 SWT JAR 文件从 Eclipse 复制到其他编辑器的类路径中。

我认为没有任何非 Eclipse SWT GUI 设计器。

于 2012-09-18T13:39:42.477 回答