final Composite topComposite=new Composite(shell, SWT.NONE); 
     RowLayout topComposite_layout=new RowLayout(); 
     topComposite_layout.type=SWT.VERTICAL; 
       topComposite.setLayout(topComposite_layout); 
         
         
        Tree tree = new Tree(topComposite, SWT.FULL_SELECTION ); 
        TreeItem root = new TreeItem(tree, SWT.NULL); 
         
        root.setText("root"); 
        for (int i = 0; i  < 10; i++) { 
            TreeItem item = new TreeItem(root, SWT.NULL); 
            item.setText("Item"+i); 
            Image find_image_xiao=new Image(item.getDisplay(), 
       "E:\\java\\myeclipse'workspace\\XXX_SW\\" + 
       "image\\test_image\\frind5hao.png"); 
            item.setImage(find_image_xiao); 
        } 
能成功运行的,但是tree时缩在一个很小的方块里边,只能看到一个item.... 自动添加了滚动条了。。 root.setSize(...);也没用啊 帮帮我啊  谢谢!~~

解决方案 »

  1.   

    这样改:
    shell.setLayout(new FillLayout());
    Composite topComposite = new Composite(shell, SWT.NONE);
    // RowLayout topComposite_layout = new RowLayout();
    // topComposite_layout.type = SWT.VERTICAL;
    // topComposite.setLayout(topComposite_layout);
    topComposite.setLayout(new FillLayout()); Tree tree = new Tree(topComposite, SWT.FULL_SELECTION);
    TreeItem root = new TreeItem(tree, SWT.NULL);
    root.setText("root");
    for (int i = 0; i < 10; i++) {
    TreeItem item = new TreeItem(root, SWT.NULL);
    item.setText("Item" + i);
     Image find_image_xiao = new Image(item.getDisplay(),
    "E:\\java\\myeclipse'workspace\\XXX_SW\\"
    + "image\\test_image\\frind5hao.png");
    item.setImage(find_image_xiao);
    }
      

  2.   

    这样,上一个写多了.
    汗ing...
    final Composite topComposite = new Composite(shell, SWT.NONE);
    // RowLayout topComposite_layout = new RowLayout();
    // topComposite_layout.type = SWT.VERTICAL;
    // topComposite.setLayout(topComposite_layout);
    topComposite.setLayout(new FillLayout()); Tree tree = new Tree(topComposite, SWT.FULL_SELECTION);
    TreeItem root = new TreeItem(tree, SWT.NULL);
    root.setText("root");
    for (int i = 0; i < 10; i++) {
    TreeItem item = new TreeItem(root, SWT.NULL);
    item.setText("Item" + i);
     Image find_image_xiao = new Image(item.getDisplay(),
    "E:\\java\\myeclipse'workspace\\XXX_SW\\"
    + "image\\test_image\\frind5hao.png");
    item.setImage(find_image_xiao);
    }