<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 89,  comments - 98,  trackbacks - 0

    SWT當中的GridLayout是一個非常靈活的控件,但是在使用起來需要在控制上下一番功夫.

    大家都知道,JAVA在寫編寫窗口程序的時候,物件的添加,放置 操作起來要比.net費勁的多,但是如果用好了相關org.eclipse.layout.*包當中的相關類,也會寫出十分漂亮的界面程序.

    下面大家先看一個程序:

    源碼如下:

    package com.layout;

    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.SWT;

    public class CopyOfGridLayoutExc {
    ?
    ?public static void main(String[] args) {

    ??Display display = new Display();

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

    ???? shell.setText("Find (GridLayout)");

    ???? Label label = new Label(shell, SWT.NONE);

    ???? label.setText("Find what:");

    ???? Text text = new Text(shell, SWT.BORDER);

    ???? Button findButton = new Button(shell, SWT.PUSH);

    ???? findButton.setText("Find Next");

    ???? Group group = new Group(shell, SWT.NONE);

    ???? group.setLayout(new RowLayout());

    ???? Button upButton = new Button(group, SWT.RADIO);

    ???? upButton.setText("Up");

    ???? Button downButton = new Button(group, SWT.RADIO);

    ???? downButton.setText("Down");

    ???? downButton.setSelection(true);

    ???? group.setText("Direction");

    ???? Button cancelButton = new Button(shell, SWT.PUSH);

    ???? cancelButton.setText("Cancel");

    ?

    ???? /* Use a GridLayout to position the controls */

    ???? Monitor monitor = shell.getMonitor();

    ???? int width = monitor.getClientArea().width / 10;

    ???? GridLayout layout = new GridLayout(4, false);

    ???? layout.marginWidth = layout.marginHeight = 14;//layout leave's the window's space

    ???? shell.setLayout(layout);

    ???? GridData labelData =

    ???????? new GridData(SWT.FILL, SWT.CENTER, false, false);

    ???? label.setLayoutData(labelData);

    ???? GridData textData =

    ???????? new GridData(SWT.FILL,SWT.CENTER,true,false,2,1);

    ???? textData.widthHint = width;

    ???? text.setLayoutData(textData);

    ???? GridData findData =

    ???????? new GridData(SWT.FILL, SWT.CENTER, false, false);

    ???? findButton.setLayoutData(findData);

    ???? GridData groupData =

    ???????? new GridData(SWT.RIGHT,SWT.TOP,false,false,3,1);

    ???? group.setLayoutData(groupData);

    ???? GridData cancelData =

    ???????? new GridData(SWT.FILL, SWT.TOP, false, false);

    ???? cancelButton.setLayoutData(cancelData);

    ?

    ???? shell.pack();

    ???? shell.open();

    ???? while (!shell.isDisposed()) {

    ???????? if (!display.readAndDispatch()) display.sleep();

    ???? }

    ???? display.dispose();

    ?}

    }



    這其中我們在使用的時候應該要注意以下幾點:

    1.要選擇自己適合 的Layout類型.GridLayout適合于多種情況,它大部分情況是使用在較為復雜的界面編程當中,因為復雜的界面會有相當多的控件.



    2.GridData的使用將是一個控制界面顯示的主要類.通過使用GridData我們可以很好的控制界面.

    ?? 其中GridData的構造函數比較多,但是相關的使用我們都應該熟悉,特別是上面源程序當中使用的那個構造函數,在使用起來更容易控制GridLayout的布局.通過horizantalSpan,VerticalSpan來控制控件所占用的單元格,這樣就會控制其它控制是否在一列當中顯示還是在幾列當中顯示.前提是通過GridLayout.numColumns來設置列數.

    3.如果不設置GridData那么相關的控件都會按照相關的建立順序加入到GridLayout當中.GridData不能控制控件的顯示順序,而相關順序是對象的建立順序來控制的.這一點不要與GridData混淆了.

    希望寫這篇文章對大家學習SWT有用.


    posted on 2006-09-12 10:50 水煮三國 閱讀(2491) 評論(1)  編輯  收藏 所屬分類: J2SE

    FeedBack:
    # re: SWT:GridLayout 的使用需要注意的事項[未登錄]
    2008-05-26 09:20 | javaboy
    呵呵 學習了 在我主頁上轉載了  回復  更多評論
      
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(4)

    隨筆分類(85)

    隨筆檔案(89)

    文章分類(14)

    文章檔案(42)

    收藏夾(37)

    java

    oracle

    Sybase

    搜索

    •  

    積分與排名

    • 積分 - 211831
    • 排名 - 266

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 香蕉97碰碰视频免费| 亚洲人成电影青青在线播放| 国产在线观a免费观看| 亚洲国产成人资源在线软件| 国产精品久久久久免费a∨| 日韩精品免费一线在线观看| 亚洲人成7777影视在线观看| 中文亚洲AV片在线观看不卡| 好爽又高潮了毛片免费下载| 99精品视频在线视频免费观看| 美女视频黄频a免费| 亚洲人成电影青青在线播放| 亚洲av中文无码乱人伦在线播放 | 免费黄色电影在线观看| 免费人成视频在线观看免费| 亚洲一本到无码av中文字幕| 久久99亚洲网美利坚合众国| 亚洲精品美女久久久久99小说| 女人让男人免费桶爽30分钟| 日本精品人妻无码免费大全| ww4545四虎永久免费地址| 免费无码又爽又刺激一高潮| 免费看黄的成人APP| 国产精品免费福利久久| 99久久免费国产精品热| 成人A片产无码免费视频在线观看 成人电影在线免费观看 | 久久福利资源网站免费看| 拍拍拍无挡免费视频网站| 无码精品国产一区二区三区免费| 亚洲精品人成网线在线播放va| 中文有码亚洲制服av片| 国产精品久久久久久亚洲影视| 亚洲成在人线在线播放无码| 自拍偷自拍亚洲精品播放| 免费中文字幕视频| 久久免费精品一区二区| 亚欧在线精品免费观看一区| 性xxxx视频播放免费| 日本亚洲成高清一区二区三区| 亚洲午夜精品国产电影在线观看| 国产精品亚洲专区无码牛牛|