2012-11-27 52 views
0

我对SWT编程颇为陌生。我有一个GridLayout。当我第一次启动GUI时,它只在左上角显示一个Button。如果我调整它的大小(使窗口变大或变小),我就得到了我想要的GUI。我修改了构造函数和open()方法,但是我所做的每个更改都没有改变。在swt中调整大小问题

 // 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(); 
+1

您能否发布完整的代码? – Baz

+1

尝试在打开外壳之前设置布局。 –

+0

好的建议 - 我需要做的是从构造函数中移动一些初始化,并打开createContents()方法。 – brifer

回答

0

的代码应该是:

Display display = Display.getDefault(); 
Shell shell = new Shell(display); 
shell.setLayout(new GridLayout(2, true)); 
createContents(shell); 
shell.pack(); 
shell.open(); 

你根据其内容缺少shell.pack();这将大小的外壳。


BTW:Here是一个非常漂亮的模板,可以用来作为起点,几乎所有的SWT应用程序。

+0

感谢baz,很好的建议 - 我需要做的是从构造函数中移动一些初始化,并打开createContents()方法。 – brifer