最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SWT(JFace)體驗之GridLayout布局

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

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

GridLayout的風(fēng)格

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

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

MakeColumnsEqualWidth:通過“gridLayout. makeColumnsEqualWidth”屬性可以設(shè)置父組件中子組件是否有相同的列寬,當(dāng)MakeColumnsEqualWidth為true時表示每列的列寬相等。
MarginLeft:表示當(dāng)前組件距離父組件左邊距的像素點個數(shù)。
MarginRight:表示當(dāng)前組件距離父組件右邊距的像素點個數(shù)。
MarginTop:表示當(dāng)前組件距離父組件上邊距的像素點個數(shù)。
MarginBottom:表示當(dāng)前組件距離父組件下邊距的像素點個數(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:表示水平對齊方式。

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

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

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

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

測試代碼:

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

下面這個例子布局稍微復(fù)雜一點:
復(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)格式布局,它把父組件分成一個表格,默認(rèn)情況下每個子組件占據(jù)一個單元格的空間,每個子組件按添加到父組件的順序排列在表格中。

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

14.11.1 GridLayout的風(fēng)格

GridLayout類提供了GridLayout 布局中劃分網(wǎng)格的信息,主要通過以下幾個參數(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時表示每列的列寬相等。

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

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

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

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

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

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

相關(guān)文章

  • java實現(xiàn)2048小游戲(含注釋)

    java實現(xiàn)2048小游戲(含注釋)

    這篇文章主要為大家介紹了java實現(xiàn)2048小游戲,含詳細(xì)注釋,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • springboot接收前端參數(shù)的四種方式圖文詳解

    springboot接收前端參數(shù)的四種方式圖文詳解

    Spring Boot可以通過多種方式接收前端傳遞的數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于springboot接收前端參數(shù)的四種方式,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • Java實現(xiàn)產(chǎn)生隨機(jī)字符串主鍵的UUID工具類

    Java實現(xiàn)產(chǎn)生隨機(jī)字符串主鍵的UUID工具類

    這篇文章主要介紹了Java實現(xiàn)產(chǎn)生隨機(jī)字符串主鍵的UUID工具類,涉及java隨機(jī)數(shù)與字符串遍歷、轉(zhuǎn)換等相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • 基于java語言實現(xiàn)快遞系統(tǒng)

    基于java語言實現(xiàn)快遞系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了基于java語言實現(xiàn)快遞系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 理解Java當(dāng)中的回調(diào)機(jī)制(翻譯)

    理解Java當(dāng)中的回調(diào)機(jī)制(翻譯)

    今天我要和大家分享一些東西,舉例來說這個在JavaScript中用的很多。我要講講回調(diào)(callbacks)。你知道什么時候用,怎么用這個嗎?你真的理解了它在java環(huán)境中的用法了嗎?當(dāng)我也問我自己這些問題,這也是我開始研究這些的原因
    2014-10-10
  • java Socket UDP實例詳解

    java Socket UDP實例詳解

    這篇文章主要介紹了java Socket UDP實例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Java實現(xiàn)簡單的掃雷小程序

    Java實現(xiàn)簡單的掃雷小程序

    這篇文章主要為大家詳細(xì)介紹了Java實現(xiàn)簡單的掃雷小程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • Java利用條件運(yùn)算符的嵌套來完成學(xué)習(xí)成績的劃分

    Java利用條件運(yùn)算符的嵌套來完成學(xué)習(xí)成績的劃分

    這篇文章主要介紹了Java利用條件運(yùn)算符的嵌套來完成學(xué)習(xí)成績的劃分,需要的朋友可以參考下
    2017-02-02
  • Java使用OpenCV進(jìn)行圖像處理的示例代碼

    Java使用OpenCV進(jìn)行圖像處理的示例代碼

    OpenCV是一個開源的計算機(jī)視覺庫,廣泛應(yīng)用于圖像處理、機(jī)器學(xué)習(xí)和計算機(jī)視覺等領(lǐng)域,盡管OpenCV主要使用C/C++進(jìn)行開發(fā),但它也為Java提供了綁定,使得Java開發(fā)者能夠利用其強(qiáng)大的圖像處理功能,在本篇文章中,我們將詳細(xì)介紹如何在Java中使用OpenCV,需要的朋友可以參考下
    2025-03-03
  • Springboot集成JUnit5優(yōu)雅進(jìn)行單元測試的示例

    Springboot集成JUnit5優(yōu)雅進(jìn)行單元測試的示例

    這篇文章主要介紹了Springboot集成JUnit5優(yōu)雅進(jìn)行單元測試的示例,幫助大家更好的理解和使用springboot框架,感興趣的朋友可以了解下
    2020-10-10

最新評論

乌苏市| 遵义市| 英山县| 筠连县| 秭归县| 秭归县| 乐都县| 梧州市| 荔波县| 德化县| 盐源县| 罗甸县| 靖远县| 荣成市| 府谷县| 宜君县| 陵川县| 东宁县| 河曲县| 舟曲县| 赤水市| 高州市| 大理市| 南阳市| 太湖县| 宽甸| 安徽省| 恩平市| 武夷山市| 株洲县| 巫溪县| 珲春市| 英山县| 聂拉木县| 永兴县| 天峻县| 潼关县| 霍邱县| 昆明市| 论坛| 胶南市|