posts - 1,  comments - 25,  trackbacks - 0
First , The nomal composite is very different from the Table Viewer and Tree Viewer.
The Table viewer and Tree Viewer only need add the SWT.H_SCROLL and SWT.V_SCROLL into  the Constructor. The context will be move with scroll bar.
This is because the viewer has been include the scrollabled composite. 

So . nomal composite should implment the scrollableComposte by ourself.

        1. Set parent compsoite's layout as FillLayout.   

       parentComposite.setLayout(new FillLayout());
        ScrolledComposite scrolledComposite = new ScrolledComposite(parentComposite,  SWT.H_SCROLL|SWT.V_SCROLL);
        
         2. Create the main composite and use the scrolled Composite as it's father.
        Composite mainComposite = new Composite(scrolledComposite,SWT.NONE);

        3. Set scrolled composite can controll the main composite.
        scrolledComposite.setContent(mainComposite);
        mainComposite.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WHITE));// White color
        mainComposite.setLayout(new GridLayout(1,true));
        GridData data = new GridData(GridData.FILL_BOTH);
        mainComposite.setLayoutData(data);
         
       4. Set the other attributes.        
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
        scrolledComposite.setMinWidth(800);
        scrolledComposite.setMinHeight(400);


 总结:
 1)在为Composite添加滚动条时,最上面的Composite的布局需设为FillLayout();
 2) 不要直接往scrolledComposite上面添加控件;
 3) 在创建完ScrolledComposite后不要忘记使用setContent()方法去设置滚动条所控制的Composite;
 4) 最重要的是,Scrolledcomposite的以下四个参数必须设置才能出现滚动条:
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setMinWidth(800);
    scrolledComposite.setMinHeight(400);
    只有前两项设为true之后,后面的两项才起作用。
5) 对于setMinWidth()和setMinHeight()方法,API的注释中是说用来设置滚动条出现的最小宽度和高度,但是我试了一下,有时出现滚动条了,
    但是拖动滚动条还是不能显示Composite里面的全部内容,于是把setMinWidth()和setMinHeight()设大一些就可以了,个人感觉滚动条出现的
    宽度和高度检测Scrolledcomposite自己已经实现了,这里的宽度和高度是指拖动滚动条里可以看到的Composite的最大宽度和最大高度。

posted on 2009-03-20 16:37 Daniel 阅读(366) 评论(0)  编辑  收藏 所属分类: SWT

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论