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