Java 在swt中调整问题的大小
我对SWT编程相当陌生。我有一个Java 在swt中调整问题的大小,java,user-interface,resize,swt,grid-layout,Java,User Interface,Resize,Swt,Grid Layout,我对SWT编程相当陌生。我有一个网格布局。当我第一次启动GUI时,它只在左上角显示一个按钮。如果我调整它的大小(使窗口变大或变小),我就会得到我想要的GUI。我已经修改了构造函数和open()方法,但是我所做的每一次更改都没有什么不同 // constructor public MyGuiApp(){ super(); shell = new Shell(); shell.setSize(250, 300); // the open method
网格布局
。当我第一次启动GUI时,它只在左上角显示一个按钮。如果我调整它的大小(使窗口变大或变小),我就会得到我想要的GUI。我已经修改了构造函数和open()
方法,但是我所做的每一次更改都没有什么不同
// constructor
public MyGuiApp(){
super();
shell = new Shell();
shell.setSize(250, 300);
// the open method
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.setLayout(new GridLayout(2,true));
// instantiation
public static void main(String args[]) {
try {
MyGuiApp window = new MyGuiApp();
window.open();
代码应为:
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2, true));
createContents(shell);
shell.pack();
shell.open();
您缺少shell.pack()代码>将根据壳的内容调整壳的大小
顺便说一句:这是一个非常好的模板,几乎可以作为任何SWT应用程序的起点。你能发布完整的代码吗?在打开shell之前尝试设置布局。好的建议-我需要做的是将一些初始化从构造函数和打开方法移到createContents()。@BrianFeran下次,编译的post代码。否则很难看出哪里出了问题。谢谢baz,好的建议-我需要做的是将一些初始化从构造函数和open方法移到createContents()。