SWT的ExpandBar的使用

來源:互聯網
上載者:User

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 />

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.