SWT的ExpandBar的使用

import org.eclipse.jface.resource.JFaceResources;  
import org.eclipse.swt.SWT;  
import org.eclipse.swt.graphics.Font;  
import org.eclipse.swt.layout.FillLayout;  
import org.eclipse.swt.layout.GridLayout;  
import org.eclipse.swt.widgets.Composite;  
import org.eclipse.swt.widgets.Display;  
import org.eclipse.swt.widgets.ExpandBar;  
import org.eclipse.swt.widgets.ExpandItem;  
import org.eclipse.swt.widgets.Label;  
import org.eclipse.swt.widgets.Link;  
import org.eclipse.swt.widgets.Shell;  
public class TestExpandBar {  
    public TestExpandBar() {  
        final Display display = Display.getDefault();  
        final Shell shell = new Shell(SWT.MIN);  
        shell.setText("ExpandBar練習");  
        shell.setSize(200, 518);  
        shell.setLayout(new FillLayout());  
        ExpandBar expandBar = new ExpandBar(shell, SWT.V_SCROLL);  
        {  
            Composite comp1 = new Composite(expandBar, SWT.NONE);  
            comp1.setLayout(new GridLayout(2, false));  
            new Link(comp1, SWT.NONE).setText("<a>查看系統信息</a>");  
            new Link(comp1, SWT.NONE).setText("<a>添加/刪除程序</a>");  
            new Link(comp1, SWT.NONE).setText("<a>更改一個設置</a>");  
            ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);  
            item1.setText("系統任務");  
            item1.setHeight(75);// 設置Item的高度  
            item1.setControl(comp1);// setControl方法控制comp1的顯現  
        }  
        {  
            Composite comp2 = new Composite(expandBar, SWT.NONE);  
            comp2.setLayout(new GridLayout(2, false));  
            new Link(comp2, SWT.NONE).setText("<a>網上鄰居</a>");  
            new Link(comp2, SWT.NONE).setText("<a>我的文檔</a>");  
            new Link(comp2, SWT.NONE).setText("<a>共享文檔</a>");  
            new Link(comp2, SWT.NONE).setText("<a>控制面板</a>");  
            ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);  
            item1.setText("其他位置");  
            item1.setHeight(95);// 設置Item的高度  
            item1.setControl(comp2);// setControl方法控制comp1的顯現  
        }  
        {  
            Composite comp3 = new Composite(expandBar, SWT.NONE);  
            comp3.setLayout(new GridLayout());  
            // setup bold font  
            Font boldFont = JFaceResources.getFontRegistry().getBold(  
                    JFaceResources.DEFAULT_FONT);  
            Label l = new Label(comp3, SWT.NONE);  
            l.setText("我的電腦");  
            l.setFont(boldFont);  
            new Label(comp3, SWT.NONE).setText("系統文件夾");  
            ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE);  
            item1.setText("詳細信息");  
            item1.setHeight(50);// 設置Item的高度  
            item1.setControl(comp3);// setControl方法控制comp1的顯現  
        }  
    //  shell.layout();  
        shell.open();  
        while (!shell.isDisposed()) {  
            if (!display.readAndDispatch())  
                display.sleep();  
        }  
        display.dispose();  
    }  
    public static void main(String[] args) {  
        new TestExpandBar();  
    }  


本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/naughty610/archive/2010/02/16/5309552.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章