SWT(JFace)體驗之FillLayout布局
更新時間:2009年06月25日 11:11:07 作者:
FillLayout是非常簡單的一種布局方式,它會以同樣大小對父組件中的子組件進行布局,這些子組件將以一行或一列的形式排列。
FillLayout布局
FillLayout是非常簡單的一種布局方式,它會以同樣大小對父組件中的子組件進行布局,這些子組件將以一行或一列的形式排列。一般來說,用戶可以在任務欄、工具欄中放置FillLayout布局,通過FillLayout布局對子組件進行定位,也可以當子組件只有一個組件時,通過FillLayout布局填充整個父組件的空間。
FillLayout的風格
FillLayout布局中,可以把子組件按水平或垂直的方式進行排列,這些風格是當創(chuàng)建FillLayout實類時以參數形式指定的。
演示代碼:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FillLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public FillLayoutSample() {
FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
fillLayout.marginHeight = 5;
fillLayout.marginWidth = 5;
fillLayout.spacing = 1;
shell.setLayout(fillLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new FillLayoutSample();
}
}
FillLayout是非常簡單的一種布局方式,它會以同樣大小對父組件中的子組件進行布局,這些子組件將以一行或一列的形式排列。一般來說,用戶可以在任務欄、工具欄中放置FillLayout布局,通過FillLayout布局對子組件進行定位,也可以當子組件只有一個組件時,通過FillLayout布局填充整個父組件的空間。
FillLayout的風格
FillLayout布局中,可以把子組件按水平或垂直的方式進行排列,這些風格是當創(chuàng)建FillLayout實類時以參數形式指定的。
演示代碼:
復制代碼 代碼如下:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FillLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
public FillLayoutSample() {
FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
fillLayout.marginHeight = 5;
fillLayout.marginWidth = 5;
fillLayout.spacing = 1;
shell.setLayout(fillLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button number 2");
Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new FillLayoutSample();
}
}
相關文章
詳解Java如何在CompletableFuture中實現日志記錄
這篇文章主要為大家詳細介紹了一種slf4j自帶的MDC類,來記錄完整的請求日志,和在CompletableFuture異步線程中如何保留鏈路id,需要的可以參考一下2023-04-04Springboot中使用攔截器、過濾器、監(jiān)聽器的流程分析
Javaweb三大組件:servlet、Filter(過濾器)、?Listener(監(jiān)聽器),這篇文章主要介紹了Springboot中使用攔截器、過濾器、監(jiān)聽器的流程分析,感興趣的朋友跟隨小編一起看看吧2023-12-12Spring實戰(zhàn)之讓Bean獲取Spring容器操作示例
這篇文章主要介紹了Spring實戰(zhàn)之讓Bean獲取Spring容器操作,結合實例形式分析了Bean獲取Spring容器的相關原理、實現方法及操作注意事項,需要的朋友可以參考下2019-11-11如何通過自定義spring?invalidator注解校驗數據合法性
這篇文章主要介紹了如何通過自定義spring?invalidator注解校驗數據合法性,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07SpringBoot @PostMapping接收HTTP請求的流數據問題
這篇文章主要介紹了SpringBoot @PostMapping接收HTTP請求的流數據問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02如何使用Spring?integration在Springboot中集成Mqtt詳解
MQTT是多個客戶端通過一個中央服務器傳遞信息的多對多協(xié)議,能高效地將信息分發(fā)給一個或多個訂閱者,下面這篇文章主要給大家介紹了關于如何使用Spring?integration在Springboot中集成Mqtt的相關資料,需要的朋友可以參考下2023-02-02