我想使用 swt 来制作 GUI,但我不想使用 eclipse 来编程。有没有办法做到这一点。另外,有没有 swt 的 GUI 设计器不是 eclipse 插件的。
最佳答案
当然可以独立于 Eclipse-RCP 平台使用 SWT。你只需要有合适的 jar 。查看这些示例 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/
关于java - 如何在没有 Eclipse 的情况下使用 SWT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12478069/