刚学 SWT,本以为很简单的,但是运行程序的时候老是有问题,明明没有错误显示,但是运行下面的程序以后只显示了主窗口,不知道怎么回事,心都凉了public class FenZuKuang { /**
 * @param args
 */
public static void main(String[] args) {
// TODO 自动生成方法存根
final Display display=Display.getDefault();
final Shell shell=new Shell();
shell.setText("服务器管理");
final Composite composite=new Composite(shell,SWT.NONE);
composite.setBounds(20,30,800,500);

        
        //建立三个分组框
        // 第一个分组框
         final Group group1=new Group(composite,SWT.NONE);
         group1.setText("有效更新");
         final Button button11=new Button(group1,SWT.RADIO);
         button11.setText("等价版本(1.0.1 -> 1.0.2 - 仅服务版本增加) (Q)");
         final Button button12=new Button(group1,SWT.RADIO);
         button12.setText("兼容版本(1.0.9 -> 1.1.0 - 服务版本和次版本增加) (C)");
        
        //第二个分组框
         final Group group2=new Group(composite,SWT.NONE);
         group2.setText("更新策略 (U)"); 
         final Label label21=new Label(group2,SWT.NONE);
         label21.setText("策略 URL:");
         new Text(group2,SWT.NONE);
         
          
        //第三个分组框
         final Group group3=new Group(composite,SWT.NONE);
         group3.setText("代理设置");
         final Button button3=new Button(group3,SWT.CHECK);
         button3.setText("启用 HTTP 代理连接(N)");
         final Label label31=new Label(group3,SWT.NONE);
         label31.setText("HTTP 代理主机地址: ");
         final Text text31=new Text(group3,SWT.NONE);
         
         final Label label32=new Label(group3,SWT.NONE);
         label32.setText("HTTP 代理主机端口: ");
         final Text text32=new Text(group3,SWT.NONE);
         
         button3.addSelectionListener(new SelectionAdapter(){
          public void widgetSelected(SelectionEvent e){
          if(button3.getSelection())
          {
              label31.setEnabled(true);
              text31.setEnabled(true);
              label32.setEnabled(true);
              text32.setEnabled(true);
          }
          else
          {
           label31.setEnabled(false);  
           text31.setEnabled(false);
           label32.setEnabled(true);
              text32.setEnabled(true);
          }
          }
          });
         
         shell.layout();
        shell.open();
while(!composite.isDisposed()){//如果主窗口没有关闭,则一直循环
if(!display.readAndDispatch())//如果主窗口不忙,就让Display处在休眠状态
display.sleep();
}
display.dispose();//释放display资源
}
}

解决方案 »

  1.   

    // 第一个分组框 
             final Group group1=new Group(composite,SWT.NONE); 
             group1.setText("有效更新"); 
    在这个后面添加group1.setBounds(50,50,100,100);就看得到了
      

  2.   

    我个人使用swt的时候体会是setBounds放在所有初始化的最后,否则也显示不出来
      

  3.   

    你需要给shell设置Layout,给composite设置LayoutData
    你需要明白几点:
    1,Layout:用来表示当前这个容器是怎么划分的
    2,LayoutData:表示当前这个对象在它父对象上是怎么占据的!
    3,如果空间Composite里面需要添加组件的话,你必须设置它的Layout
    4,必须给没一个Composite设置LayoutData说明其在父中怎么占据
    5,父上使用了某个layout,则子控件只能使用相应的data。如:GridLayout上只能使用GridData
    你的代码解决办法是:
    1,在[shell.setText("服务器管理"); ]后添加如下代码
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = gridLayout.marginWidth = 1;
    shell.setLayout(gridLayout);
    2,在[final Composite composite=new Composite(shell,SWT.NONE); ]后添加如下代码:
    composite.setLayout(new GridLayout(1,true));
    3,然后你自己领会一下,现在能看到东西了,怎么美化他就是你的事情了!有问题继续联络!
      

  4.   

    ??!!!居然每个控件你都没有setBounds()这个方法??!!你去下一个SWT Designer_v6.5.0_for_Eclipse3.3 吧,这样你可以进行可视化开发了!!!
      

  5.   

    不是每个控件都需要setBounds()的,一般情况只需要给shell.setSize()就ok了
    其他组件的分布完全可以用Layout和LayoutData去控制,不要误解!!!!!
      

  6.   


    setBounds是一种比较死板的固定显示方式,不推荐,建议使用Layout LayoutData      qingkangxu的解释很详细```
    要真正去理解
      

  7.   

    统一楼上的说法,要使用Layout 和LayoutData进行界面的布局