程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> SWT(JFace)體驗之RowLayout結構

SWT(JFace)體驗之RowLayout結構

編輯:關於JAVA

SWT(JFace)體驗之RowLayout結構。本站提示廣大學習愛好者:(SWT(JFace)體驗之RowLayout結構)文章只能為提供參考,不一定能成為您想要的結果。以下是SWT(JFace)體驗之RowLayout結構正文


RowLayout結構 

絕對於FillLayout來講,RowLayout比擬靈巧,功效也比擬強。用戶可以設置結構中子元素的年夜小、邊距、換行及間距等屬性。

RowLayout的作風

RowLayout中可以以相干的屬性設定結構的作風,用戶可以經由過程“RowLayout.屬性”的方法設置RowLayout的結構作風,RowLayout中經常使用的屬性以下。
Wrap:表現子組件能否可以換行(true為可換行)。
Pack:表現子組件能否為堅持原有年夜小(true為堅持原有年夜小)。
Justify:表現子組件能否依據父組件信息做調劑。
MarginLeft:表現以後組件間隔父組件右邊距的像素點個數。
MarginTop:表現以後組件間隔父組件上邊距的像素點個數。
MarginRight:表現以後組件間隔父組件左邊距的像素點個數。
MarginBottom:表現以後組件間隔父組件下邊距的像素點個數。
Spacing:表現子組件之間的間距像素點個數。

別的,RowLayout可以經由過程RowData設置每一個子組件的年夜小,例如“button.setLayoutData (new RowData(60, 60))”將設置button的年夜小為(60,60)。
測試代碼:

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();
}
}

再看看上面這個靜態的(聯合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();
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved