




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、實戰(zhàn)SWT之FormLayout/分割窗口/菜單/狀態(tài)欄(2006-11-03 08:51:37) 轉(zhuǎn)載 分類:IT技術(shù)為了編寫桌面應(yīng)用程序,因為用JAVA來寫,SWT是一個非常好的工具包,近來有使用了一個很好的布局FormLayout,它是用控件的四個頂點的位置來定位一個控件及它的大小的。下面的抓圖是我布局好的一個符合窗口,大家一定見慣了這樣的窗口。窗口最上方的是菜單Menu,沒有寫子菜單;中間部分是一個分割窗口SashForm,分割窗口的左邊是一棵樹Tree,右邊是一個標(biāo)簽頁TabFolder;最下面的是一個狀態(tài)欄CoolBar。窗口的布局與界面顯示完全是WINDOWS的風(fēng)格,
2、不需要自己動手寫代碼來實現(xiàn)復(fù)雜的界面布局。下面是源代碼。package test.base;import org.eclipse.swt.layout.FormAttachment;import org.eclipse.swt.layout.FormData;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.TabFolder;import org.eclip
3、se.swt.SWT;import org.eclipse.swt.layout.FormLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.TabItem;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.MenuItem;import org.eclipse.swt.widgets.CoolBar;import org.eclipse
4、.swt.widgets.TreeItem;import org.eclipse.swt.custom.SashForm;import org.eclipse.swt.widgets.Tree;public class TestView private Shell sShell = null; / jve:decl-index=0:visual-constraint="10,10"private Menu menuBar = null;private CoolBar coolBar = null;private SashForm sashForm = null;privat
5、e TabFolder tabFolder = null;private Tree tree = null;private void createSShell() sShell = new Shell();sShell.setText("Shell");createCoolBar();createSashForm();sShell.setSize(new Point(300, 200);sShell.setLayout(new FormLayout();menuBar = new Menu(sShell, SWT.BAR);createMenuBar();sShell.se
6、tMenuBar(menuBar);private void createMenuBar() MenuItem push = new MenuItem(menuBar, SWT.PUSH);push.setText("文件");MenuItem push1 = new MenuItem(menuBar, SWT.PUSH);push1.setText("編輯");MenuItem push2 = new MenuItem(menuBar, SWT.PUSH);push2.setText("窗口");MenuItem push3 = n
7、ew MenuItem(menuBar, SWT.PUSH);push3.setText("幫助");private void createCoolBar() coolBar = new CoolBar(sShell, SWT.NONE);FormData formData = new FormData();formData.left = new FormAttachment(00, 0);formData.right = new FormAttachment(100, -0);formData.top = new FormAttachment(100, -24);form
8、Data.bottom = new FormAttachment(100, 0);coolBar.setLayoutData(formData);Color color = new Color(Display.getCurrent(), 0,0,0);coolBar.setBackground(color);private void createSashForm() sashForm = new SashForm(sShell, SWT.NONE);FormData formData = new FormData();formData.left = new FormAttachment(0,
9、3);formData.right = new FormAttachment(100, -3);formData.top = new FormAttachment(0, 0);formData.bottom = new FormAttachment(100, -25);sashForm.setLayoutData(formData);tree = new Tree(sashForm, SWT.NONE);createTree();createTabFolder();sashForm.setWeights(new int 1, 3);private void createTree() TreeI
10、tem treeItem = new TreeItem(tree, SWT.NONE);treeItem.setText("根結(jié)點");private void createTabFolder() tabFolder = new TabFolder(sashForm, SWT.NONE);TabItem tabItem = new TabItem(tabFolder, SWT.NONE);tabItem.setText("屬性標(biāo)簽");Label label = new Label(tabFolder, SWT.NONE);label.setText(&
11、quot;文字標(biāo)簽");tabItem.setControl(label);formData.left = new FormAttachment(0, 3);第一個參數(shù)0表示父控件寬度的0%,第二個參數(shù)3表示離左邊的距離為3pix。這樣一來左邊位置就是(width*0%+3)。formData.right = new FormAttachment(100, -3);第一個參數(shù)100表示父寬度的100%,第二個參數(shù)-3表示離左邊的距離為-3pix。這樣一來右邊位置就是(width*100%-3)。formData.top = new FormAttachment(0, 0);第一個參數(shù)0表示父控件高度的0%,第二個參
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高速鐵路設(shè)備采購合同終止及運營維護(hù)協(xié)議
- 餐飲業(yè)專用商業(yè)房產(chǎn)租賃協(xié)議書
- 老人兒童護(hù)理課件
- 美術(shù)課件彩虹模板
- 公司獎勵規(guī)章制度
- 生產(chǎn)車間10s管理制度
- 企業(yè)金融安全
- 建筑施工vr安全體驗館
- 安全防范系統(tǒng)報告
- 2025年上半年征兵工作總結(jié)
- 韶關(guān)拆除廠房施工方案
- 加油站的運營數(shù)據(jù)分析
- 食品安全日管控、周排查及月調(diào)度記錄表
- IATF 16949 質(zhì)量管理手冊
- 燃?xì)獍踩嘤?xùn)課件
- 酒店安全風(fēng)險辨識與預(yù)防制度
- 企業(yè)員工心理危機(jī)干預(yù)
- 330kV變電站運營維護(hù)管理方案
- 拋石擠淤及基礎(chǔ)大開挖施工方案
- 路燈拆裝合同范文
- 《動火作業(yè)安全培訓(xùn)》課件
評論
0/150
提交評論