麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Java > 正文

SWT(JFace)體驗之RowLayout布局

2020-01-31 16:51:43
字體:
來源:轉載
供稿:網友

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 爱逼av| 欧美一a一片一级一片 | 国产69精品久久久久久野外 | 一区二区三区欧洲 | 视频一区国产精品 | 7777在线视频免费播放 | 久国产 | 久久精品成人 | 毛片视| 免费观看黄视频 | 黄色网欧美 | 亚洲国产精品久久久 | 依依成人综合 | 成人三级电影网址 | 禁漫天堂久久久久久久久久 | 羞羞的视频在线 | 老a影视网站在线观看免费 国产精品久久久久久久久久尿 | 亚洲欧美日韩中文在线 | 日本综合久久 | 黄色片网页 | 成人免费观看49www在线观看 | 中文字幕欧美一区二区三区 | 国产亚洲精品久久久久5区 综合激情网 | 日本一道aⅴ不卡免费播放 久久久久久久高清 | 日本成人一二三区 | 一级免费黄视频 | 国产四区| 久草视频福利在线观看 | 日韩精品99久久久久久 | 中国免费一级毛片 | 国产成人在线视频播放 | 欧美日本免费一区二区三区 | 国产精品久久久久久久久粉嫩 | 欧美午夜网 | 亚洲精品欧美在线 | 一级电影在线观看 | 国产精品久久av | 亚洲人成中文字幕在线观看 | 一夜新娘第三季免费观看 | 中文字幕精品一区久久久久 | 久久久一区二区 |