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

首頁 > 編程 > Java > 正文

SWT(JFace)體驗之FormLayout布局

2020-01-31 16:51:36
字體:
來源:轉載
供稿:網友
測試代碼如下:
復制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FormLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public FormLayoutSample() {
shell.setLayout(new FormLayout());
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
FormData formData = new FormData();
formData.left = new FormAttachment(20);
formData.top = new FormAttachment(20);
button1.setLayoutData(formData);


Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");

formData = new FormData();
formData.left = new FormAttachment(button1, 0, SWT.CENTER);
formData.top = new FormAttachment(button1, 0, SWT.CENTER);
button2.setLayoutData(formData);

// Button button3 = new Button(shell, SWT.PUSH);
// button3.setText("3");
//
// formData = new FormData();
// formData.top = new FormAttachment(button2, 10);
// formData.left = new FormAttachment(button2, 0, SWT.LEFT);
// button3.setLayoutData(formData);
shell.pack();
//shell.setSize(500, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new FormLayoutSample();
}
}

再看一個例子:
復制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class Main {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
Label label = new Label(shell, SWT.WRAP);
label
.setText("This is a long text string that will wrap when the dialog is resized.");
List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
list.setItems(new String[] { "Item 1", "Item2" });
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("Ok");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("Cancel");
final int insetX = 4, insetY = 4;
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = insetX;
formLayout.marginHeight = insetY;
shell.setLayout(formLayout);
Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
final FormData labelData = new FormData(size.x, SWT.DEFAULT);
labelData.left = new FormAttachment(0, 0);
labelData.right = new FormAttachment(100, 0);
label.setLayoutData(labelData);
shell.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
Rectangle rect = shell.getClientArea();
labelData.width = rect.width - insetX * 2;
shell.layout();
}
});
FormData button2Data = new FormData();
button2Data.right = new FormAttachment(100, -insetX);
button2Data.bottom = new FormAttachment(100, 0);
button2.setLayoutData(button2Data);
FormData button1Data = new FormData();
button1Data.right = new FormAttachment(button2, -insetX);
button1Data.bottom = new FormAttachment(100, 0);
button1.setLayoutData(button1Data);
FormData listData = new FormData();
listData.left = new FormAttachment(0, 0);
listData.right = new FormAttachment(100, 0);
listData.top = new FormAttachment(label, insetY);
listData.bottom = new FormAttachment(button2, -insetY);
list.setLayoutData(listData);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 视频在线91 | 欧美一级在线看 | 懂色av懂色aⅴ精彩av | av电影在线网站 | 中文字幕亚洲一区二区三区 | 九一国产精品 | 在线成人免费视频 | 毛片在线免费视频 | 免费小毛片 | 国产精品久久久久av | 久色亚洲 | 精品一区二区三区免费视频 | 嫩草影院在线观看网站成人 | 成人男女啪啪免费观看网站四虎 | 日日狠狠久久 | ⅴideo裸体秀hd | av在线中文 | 电影91 | 亚洲欧美国产高清va在线播放 | www.91视频com | 成人黄色短视频在线观看 | 特级黄色小说 | 成人三级视频网站 | 国产精品久久久久无码av | 久久精品日产第一区二区三区 | 欧美精品一区二区久久 | 日韩黄色精品视频 | 31freehdxxxx欧美 | 一级毛片免费版 | 国产精品久久久久久久久久久久午夜 | 国产精品久久久久久久久久电影 | 羞羞答答www网站进入 | 把娇妻调教成暴露狂 | 日本网站一区二区三区 | 欧美成在人线a免费 | 欧美性生活久久久 | 精品国产一区二区久久 | 亚洲视频黄 | 姑娘第四集免费看视频 | 做羞羞视频 | 韩国精品久久久 |