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

SWT(JFace)體驗(yàn)之GridLayout布局

 更新時(shí)間:2009年06月25日 11:18:06   作者:  
GridLayout 布局的功能非常強(qiáng)大,也是筆者常用的一種布局方式。GridLayout是網(wǎng)格式布局,它把父組件分成一個(gè)表格,默認(rèn)情況下每個(gè)子組件占據(jù)一個(gè)單元格的空間,每個(gè)子組件按添加到父組件的順序排列在表格中。
GridLayout布局

GridLayout 布局的功能非常強(qiáng)大,也是筆者常用的一種布局方式。GridLayout是網(wǎng)格式布局,它把父組件分成一個(gè)表格,默認(rèn)情況下每個(gè)子組件占據(jù)一個(gè)單元格的空間,每個(gè)子組件按添加到父組件的順序排列在表格中。GridLayout提供了很多的屬性,可以靈活設(shè)置網(wǎng)格的信息。另外,GridLayout 布局提供了GridData類,子組件可以設(shè)置相應(yīng)的GridData,例如 “dogPhoto.setLayoutData(gridData)”,GridData可以設(shè)置每個(gè)組件當(dāng)做單元格的信息。

GridLayout的風(fēng)格

GridLayout類提供了GridLayout 布局中劃分網(wǎng)格的信息,主要通過以下幾個(gè)參數(shù)進(jìn)行設(shè)置。

NumColumns:通過“gridLayout.numColumns”屬性可以設(shè)置父組件中分幾列顯示子組件。

MakeColumnsEqualWidth:通過“gridLayout. makeColumnsEqualWidth”屬性可以設(shè)置父組件中子組件是否有相同的列寬,當(dāng)MakeColumnsEqualWidth為true時(shí)表示每列的列寬相等。
MarginLeft:表示當(dāng)前組件距離父組件左邊距的像素點(diǎn)個(gè)數(shù)。
MarginRight:表示當(dāng)前組件距離父組件右邊距的像素點(diǎn)個(gè)數(shù)。
MarginTop:表示當(dāng)前組件距離父組件上邊距的像素點(diǎn)個(gè)數(shù)。
MarginBottom:表示當(dāng)前組件距離父組件下邊距的像素點(diǎn)個(gè)數(shù)。
HorizontalSpacing:表示子組件的水平間距。
VerticalSpacing:表示子組件的垂直間距。

GridData的相關(guān)屬性

GridLayout布局的靈活之處在于它利用網(wǎng)格布局?jǐn)?shù)據(jù)GridData。通過GridData可以設(shè)置子組件在網(wǎng)格中的填充方式、大小邊距等信息,用戶可以通過子組件的setLayoutData方法設(shè)置網(wǎng)格布局?jǐn)?shù)據(jù)。

GridData可以控制子組件在網(wǎng)格中的位置大小等相關(guān)顯示信息。GridData可以設(shè)置如下的一些屬性。

HorizontalAlignment:表示水平對(duì)齊方式。

VerticalAlignment:表示子組件的垂直對(duì)齊方式,值和水平方式一樣。
HorizontalIndent:表示子組件水平偏移多少像素。此屬性和“horizontalAlignment = GridData.BEGINNING”屬性一起使用。

HorizontalSpan:表示組件水平占據(jù)幾個(gè)網(wǎng)格。

GrabExcessHorizontalSpace:表示當(dāng)父組件大小改變時(shí),子組件是否以水平方向搶占空間。
GrabExcessVerticalSpace:表示當(dāng)父組件大小改變時(shí),子組件是否以垂直方向搶占空間。
WidthHint:表示子組件的寬度為多少像素(前提是未設(shè)置其他相關(guān)屬性)。
HeightHint:表示子組件的高度為多少像素(前提是未設(shè)置其他相關(guān)屬性)。

另外,GridData可以通過構(gòu)造函數(shù)指定相應(yīng)的屬性值,有興趣的讀者可以參考GridData類的構(gòu)造函數(shù)。

測(cè)試代碼:

GridLayoutSample.java
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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 GridLayoutSample {

Display display = new Display();
Shell shell = new Shell(display);
public GridLayoutSample() {

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.makeColumnsEqualWidth = true;
shell.setLayout(gridLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
button1.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

List list = new List(shell, SWT.BORDER);
list.add("item 1");
list.add("item 2");
list.add("item 3");
list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button #2");
GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
gridData.horizontalIndent = 5;
button2.setLayoutData(gridData);

Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
button3.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new GridLayoutSample();
}
}

GridLayoutSampleGrabSpace.java
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class GridLayoutSampleGrabSpace {
public GridLayoutSampleGrabSpace() {

Display display = new Display();
Shell shell = new Shell(display);

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
shell.setLayout(gridLayout);

Label label = new Label(shell, SWT.BORDER);
label.setText("label");

GridData gridData3 = new GridData();
gridData3.widthHint = 60;
gridData3.heightHint = 20;

label.setLayoutData(gridData3);

Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
text.setText("text");

GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
text.setLayoutData(gridData);

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

GridData gridData2 = new GridData();
gridData2.grabExcessVerticalSpace = true;
gridData2.grabExcessHorizontalSpace = true;
gridData2.verticalAlignment = GridData.FILL;
gridData2.horizontalAlignment = GridData.FILL;

button.setLayoutData(gridData2);

shell.setSize(300, 80);
//shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new GridLayoutSampleGrabSpace();
}
}

GridLayoutSampleSpan.java
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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 GridLayoutSampleSpan {

Display display = new Display();
Shell shell = new Shell(display);
public GridLayoutSampleSpan() {

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.makeColumnsEqualWidth = true;
shell.setLayout(gridLayout);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText("button1");
button1.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

List list = new List(shell, SWT.BORDER);
list.add("item 1");
list.add("item 2");
list.add("item 3");
list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

Button button2 = new Button(shell, SWT.PUSH);
button2.setText("button #2");
GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
button2.setLayoutData(gridData);

Button button3 = new Button(shell, SWT.PUSH);
button3.setText("3");
GridData gridData2 = new GridData(GridData.VERTICAL_ALIGN_END);
gridData2.verticalSpan = 3;
button3.setLayoutData(gridData2);

shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new GridLayoutSampleSpan();
}
}

下面這個(gè)例子布局稍微復(fù)雜一點(diǎn):
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class Sample {

Display display = new Display();
Shell shell = new Shell(display);
public Sample() {
shell.setText("Book Entry Demo");
GridLayout gridLayout = new GridLayout(4, false);
gridLayout.verticalSpacing = 8;
shell.setLayout(gridLayout);
Label label = new Label(shell, SWT.NULL);
label.setText("Title: ");
Text title = new Text(shell, SWT.SINGLE | SWT.BORDER);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 3;
title.setLayoutData(gridData);
label = new Label(shell, SWT.NULL);
label.setText("Author(s): ");
Text authors = new Text(shell, SWT.SINGLE | SWT.BORDER);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 3;
authors.setLayoutData(gridData);
label = new Label(shell, SWT.NULL);
label.setText("Cover: ");
gridData = new GridData();
gridData.verticalSpan = 3;
label.setLayoutData(gridData);
CLabel cover = new CLabel(shell, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 1;
gridData.verticalSpan = 3;
gridData.heightHint = 100;
gridData.widthHint = 100;
cover.setLayoutData(gridData);
label = new Label(shell, SWT.NULL);
label.setText("Pages");
Text pages = new Text(shell, SWT.SINGLE | SWT.BORDER);
pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
label = new Label(shell, SWT.NULL);
label.setText("Publisher");
Text pubisher = new Text(shell, SWT.SINGLE | SWT.BORDER);
pubisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
label = new Label(shell, SWT.NULL);
label.setText("Rating");
Combo rating = new Combo(shell, SWT.READ_ONLY);
rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
rating.add("5");
rating.add("4");
rating.add("3");
rating.add("2");
rating.add("1");
label = new Label(shell, SWT.NULL);
label.setText("Abstract:");
Text bookAbstract =
new Text(
shell,
SWT.WRAP
| SWT.MULTI
| SWT.BORDER
| SWT.H_SCROLL
| SWT.V_SCROLL);
gridData =
new GridData(
GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
gridData.horizontalSpan = 3;
gridData.grabExcessVerticalSpace = true;
bookAbstract.setLayoutData(gridData);
Button enter = new Button(shell, SWT.PUSH);
enter.setText("Enter");
gridData = new GridData();
gridData.horizontalSpan = 4;
gridData.horizontalAlignment = GridData.END;
enter.setLayoutData(gridData);
title.setText("Professional Java Interfaces with SWT/JFace");
authors.setText("Jack Li Guojie");
pages.setText("500pp");
pubisher.setText("John Wiley & Sons");
cover.setBackground(new Image(display, "C:/eclipse32.gif"));
bookAbstract.setText(
"This book provides a comprehensive guide for \n"
+ "you to create Java user interfaces with SWT/JFace. ");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new Sample();
}
}

GridLayout 布局的功能非常強(qiáng)大,也是筆者常用的一種布局方式。GridLayout是網(wǎng)格式布局,它把父組件分成一個(gè)表格,默認(rèn)情況下每個(gè)子組件占據(jù)一個(gè)單元格的空間,每個(gè)子組件按添加到父組件的順序排列在表格中。

GridLayout提供了很多的屬性,可以靈活設(shè)置網(wǎng)格的信息。另外,GridLayout 布局提供了GridData類,子組件可以設(shè)置相應(yīng)的GridData,例如“dogPhoto.setLayoutData(gridData)”,GridData可以設(shè)置每個(gè)組件當(dāng)做單元格的信息。

14.11.1 GridLayout的風(fēng)格

GridLayout類提供了GridLayout 布局中劃分網(wǎng)格的信息,主要通過以下幾個(gè)參數(shù)進(jìn)行設(shè)置。

NumColumns:通過“gridLayout.numColumns”屬性可以設(shè)置父組件中分幾列顯示子組件,如表14-4所示。

表14-4  NumColumns效果

列    數(shù)

顯 示 效 果

numColumns = 1

 

numColumns = 2

 

numColumns = 3

 


MakeColumnsEqualWidth:通過“gridLayout. makeColumnsEqualWidth”屬性可以設(shè)置父組件中子組件是否有相同的列寬,當(dāng)MakeColumnsEqualWidth為true時(shí)表示每列的列寬相等。

MarginLeft:表示當(dāng)前組件距離父組件左邊距的像素點(diǎn)個(gè)數(shù)。

MarginRight:表示當(dāng)前組件距離父組件右邊距的像素點(diǎn)個(gè)數(shù)。

MarginTop:表示當(dāng)前組件距離父組件上邊距的像素點(diǎn)個(gè)數(shù)。

MarginBottom:表示當(dāng)前組件距離父組件下邊距的像素點(diǎn)個(gè)數(shù)。

HorizontalSpacing:表示子組件的水平間距。

VerticalSpacing:表示子組件的垂直間距。

相關(guān)文章

  • mybatis教程之resultmap_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    mybatis教程之resultmap_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了mybatis教程之resultmap,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • MyBatis核心源碼深度剖析SQL語(yǔ)句執(zhí)行過程

    MyBatis核心源碼深度剖析SQL語(yǔ)句執(zhí)行過程

    這篇文章主要介紹了MyBatis核心源碼深度剖析SQL執(zhí)行過程,mybatis執(zhí)行SQL的流程都是根據(jù)statement字符串從configuration中獲取對(duì)應(yīng)的mappedStatement,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2022-05-05
  • Java實(shí)現(xiàn)矩形碰撞檢測(cè)

    Java實(shí)現(xiàn)矩形碰撞檢測(cè)

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)矩形碰撞檢測(cè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 基于Java實(shí)現(xiàn)QQ郵箱發(fā)送工具類

    基于Java實(shí)現(xiàn)QQ郵箱發(fā)送工具類

    我們?cè)谌粘i_發(fā)中,需要實(shí)現(xiàn)一個(gè)對(duì)郵箱的發(fā)送,今天就實(shí)現(xiàn)郵箱的發(fā)送工具類,只需要一些注冊(cè)郵箱之后的配置即可,感興趣的小伙伴可以了解下
    2023-12-12
  • redis 使用lettuce 啟動(dòng)內(nèi)存泄漏錯(cuò)誤的解決方案

    redis 使用lettuce 啟動(dòng)內(nèi)存泄漏錯(cuò)誤的解決方案

    這篇文章主要介紹了redis 使用lettuce 啟動(dòng)內(nèi)存泄漏錯(cuò)誤的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • 使用SpringMVC在redirect重定向的時(shí)候攜帶參數(shù)的問題

    使用SpringMVC在redirect重定向的時(shí)候攜帶參數(shù)的問題

    這篇文章主要介紹了使用SpringMVC在redirect重定向的時(shí)候攜帶參數(shù)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Mybatis的mapper.xml中if標(biāo)簽test判斷的用法說明

    Mybatis的mapper.xml中if標(biāo)簽test判斷的用法說明

    這篇文章主要介紹了Mybatis的mapper.xml中if標(biāo)簽test判斷的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • springboot 集成支付寶支付的示例代碼

    springboot 集成支付寶支付的示例代碼

    這篇文章主要介紹了springboot 集成支付寶支付的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • java 中序列化NotSerializableException問題解決辦法

    java 中序列化NotSerializableException問題解決辦法

    這篇文章主要介紹了java 中序列化NotSerializableException問題解決辦法的相關(guān)資料,這里對(duì)序列化問題進(jìn)行描述說明,并提供解決辦法,希望能幫助到大家,需要的朋友可以參考下
    2017-08-08
  • Spring?Bean自動(dòng)裝配入門到精通

    Spring?Bean自動(dòng)裝配入門到精通

    自動(dòng)裝配是使用spring滿足bean依賴的一種方法,spring會(huì)在應(yīng)用上下文中為某個(gè)bean尋找其依賴的bean,Spring中bean有三種裝配機(jī)制,分別是:在xml中顯式配置、在java中顯式配置、隱式的bean發(fā)現(xiàn)機(jī)制和自動(dòng)裝配
    2022-08-08

最新評(píng)論