SWT(JFace)體驗(yàn)之RowLayout布局
RowLayout布局
相對(duì)于FillLayout來說,RowLayout比較靈活,功能也比較強(qiáng)。用戶可以設(shè)置布局中子元素的大小、邊距、換行及間距等屬性。
RowLayout的風(fēng)格
RowLayout中可以以相關(guān)的屬性設(shè)定布局的風(fēng)格,用戶可以通過“RowLayout.屬性”的方式設(shè)置RowLayout的布局風(fēng)格,RowLayout中常用的屬性如下。
Wrap:表示子組件是否可以換行(true為可換行)。
Pack:表示子組件是否為保持原有大?。╰rue為保持原有大小)。
Justify:表示子組件是否根據(jù)父組件信息做調(diào)整。
MarginLeft:表示當(dāng)前組件距離父組件左邊距的像素點(diǎn)個(gè)數(shù)。
MarginTop:表示當(dāng)前組件距離父組件上邊距的像素點(diǎn)個(gè)數(shù)。
MarginRight:表示當(dāng)前組件距離父組件右邊距的像素點(diǎn)個(gè)數(shù)。
MarginBottom:表示當(dāng)前組件距離父組件下邊距的像素點(diǎn)個(gè)數(shù)。
Spacing:表示子組件之間的間距像素點(diǎn)個(gè)數(shù)。
另外,RowLayout可以通過RowData設(shè)置每個(gè)子組件的大小,例如“button.setLayoutData (new RowData(60, 60))”將設(shè)置button的大小為(60,60)。
測(cè)試代碼:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
public class RowLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public RowLayoutSample() {
RowLayout rowLayout = new RowLayout();
// rowLayout.fill = true;
// rowLayout.justify = true;
// rowLayout.pack = false;
// rowLayout.type = SWT.VERTICAL;
// rowLayout.wrap = false;
shell.setLayout(rowLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
button1.setLayoutData(new RowData(100, 35));
List list = new List(shell, SWT.BORDER);
list.add("item 1");
list.add("item 2");
list.add("item 3");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button #2");
//shell.setSize(120, 120);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new RowLayoutSample();
}
}
再看看下面這個(gè)動(dòng)態(tài)的(結(jié)合Composite)
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Layouting {
Display display = new Display();
Shell shell = new Shell(display);
int count = 0;
public Layouting() {
shell.setLayout(new RowLayout());
final Composite composite = new Composite(shell, SWT.BORDER);
composite.setLayout(new RowLayout());
composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
composite.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
}
public void controlResized(ControlEvent e) {
System.out.println("Composite resize.");
}
});
Button buttonAdd = new Button(shell, SWT.PUSH);
buttonAdd.setText("Add new button");
buttonAdd.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Button button = new Button(composite, SWT.PUSH);
button.setText("Button #" + (count++));
composite.layout(true);
composite.pack();
shell.layout(true);
shell.pack(true);
}
});
shell.pack();
//shell.setSize(450, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new Layouting();
}
}
上一篇:Java進(jìn)階學(xué)習(xí):網(wǎng)絡(luò)服務(wù)器編程
欄 目:Java編程
下一篇:Java進(jìn)階:JNI使用技巧點(diǎn)滴
本文標(biāo)題:SWT(JFace)體驗(yàn)之RowLayout布局
本文地址:http://mengdiqiu.com.cn/a1/Javabiancheng/8544.html
您可能感興趣的文章
- 01-10SWT(JFace)體驗(yàn)之FormLayout布局
- 01-10SWT JFace Bookmark 制作
- 01-10SWT(JFace)小制作 BugTracker
- 01-10SWT(JFace)體驗(yàn)之StyledText類
- 01-10SWT(JFace)體驗(yàn)之GridLayout布局
- 01-10SWT JFace 拖曳效果
- 01-10SWT(JFace)體驗(yàn)之ApplicationWindow
- 01-10SWT(JFace)體驗(yàn)之復(fù)制粘貼
- 01-10SWT(JFace)體驗(yàn)之打開多個(gè)Form
- 01-10SWT(JFace)體驗(yàn)之Sash(活動(dòng)控件)


閱讀排行
本欄相關(guān)
- 01-10Java咖啡館(1)——嘆咖啡
- 01-10JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)
- 01-10Java Socket編程(三) 服務(wù)器Sockets
- 01-10Java進(jìn)階:Struts多模塊的技巧
- 01-10J2SE 1.5版本的新特性一覽
- 01-10Java Socket編程(一) Socket傳輸模式
- 01-10Java運(yùn)行時(shí)多態(tài)性的實(shí)現(xiàn)
- 01-10Java Socket編程(二) Java面向連接的類
- 01-10Java Socket編程(四) 重復(fù)和并發(fā)服務(wù)
- 01-10Java經(jīng)驗(yàn)點(diǎn)滴:處理沒有被捕獲的異常
隨機(jī)閱讀
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-10C#中split用法實(shí)例總結(jié)
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置