欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace)體驗之FormLayout布局

 更新時間:2009年06月25日 11:22:38   作者:  
SWT(JFace)體驗之FormLayout布局示例代碼。
測試代碼如下:
復制代碼 代碼如下:

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

相關文章

  • SpringBoot項目部署到騰訊云的實現(xiàn)步驟

    SpringBoot項目部署到騰訊云的實現(xiàn)步驟

    本文主要介紹了SpringBoot項目部署到騰訊云的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Java?面向對象通過new揭開對象實例化

    Java?面向對象通過new揭開對象實例化

    各位鐵汁們大家好呀,我們上次博客講了,通過?Student?student1?=?new?Student();就可以實例化一個對象,這個對象就有Student類中的所以成員變量。可是?對象student1?和?類Student到底是怎樣建立聯(lián)系的,在內存中到底發(fā)生了什么
    2022-04-04
  • Java快速排序的實現(xiàn)方法示例

    Java快速排序的實現(xiàn)方法示例

    快速排序是對冒泡排序的一種改進,下面這篇文章主要給大家介紹了關于Java快速排序的實現(xiàn)方法,文中通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2024-03-03
  • SpringBoot內存數(shù)據(jù)導出成Excel的實現(xiàn)方法

    SpringBoot內存數(shù)據(jù)導出成Excel的實現(xiàn)方法

    這篇文章主要給大家介紹了關于SpringBoot內存數(shù)據(jù)導出成Excel的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • Java數(shù)組的定義與使用

    Java數(shù)組的定義與使用

    數(shù)組是有序的元素序列,若將有限個類型相同的變量的集合命名,那么這個名稱為數(shù)組名。本文通過代碼示例詳細介紹了Java數(shù)組的定義和使用,對學習或工作有一定的幫助,需要的小伙伴歡迎閱讀
    2023-04-04
  • Spring Boot中使用RabbitMQ的示例代碼

    Spring Boot中使用RabbitMQ的示例代碼

    本篇文章主要介紹了Spring Boot中使用RabbitMQ的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • 詳解JAVA流程控制語句

    詳解JAVA流程控制語句

    這篇文章主要介紹了Java中的流程控制語句,循環(huán)等語句是Java編程中流程控制的基礎,需要的朋友可以參考下
    2017-04-04
  • java json 省市級聯(lián)實例代碼

    java json 省市級聯(lián)實例代碼

    這篇文章介紹了java json 省市級聯(lián)實例代碼,有需要的朋友可以參考一下
    2013-09-09
  • 如何用Stream解決兩層List屬性求和問題

    如何用Stream解決兩層List屬性求和問題

    這篇文章主要介紹了如何用Stream解決兩層List屬性求和問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Idea中使用Git的流程

    Idea中使用Git的流程

    這篇文章主要介紹了Idea中使用Git的流程,git是目前流行的分布式版本管理系統(tǒng)。本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2020-09-09

最新評論