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

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

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

    DANCE WITH JAVA

    開發(fā)出高質(zhì)量的系統(tǒng)

    常用鏈接

    統(tǒng)計(jì)

    積分與排名

    好友之家

    最新評論

    Jface的Hello world引出的問題

    Jface的hello World網(wǎng)上到處都是,但簡單的Hello world能引出很多需要注意的問題.
    首先大部分網(wǎng)上的jface helloworld如下:
    import org.eclipse.jface.window.ApplicationWindow;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Text;


    public class TestWindow extends ApplicationWindow {

        
    public TestWindow() {
            
    super(null);
        }

        
    protected Control createContents(Composite parent) {
            Text text 
    = new Text(parent,SWT.NONE);
            text.setText(
    "hello world");
            
    return parent;
        }

        
    public static void main(String args[]) {
            
    try {
                TestWindow window 
    = new TestWindow();
                window.setBlockOnOpen(
    true);
                window.open();
                Display.getCurrent().dispose();
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }

    }


    這個(gè)代碼是可以運(yùn)行的,而且運(yùn)行的結(jié)果也看不出什么問題。但看不出來并不代表沒有問題。下邊我們來讓問題顯現(xiàn)
    在createContents()函數(shù)中再加入一個(gè)Text代碼變成
    import org.eclipse.jface.window.ApplicationWindow;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Text;


    public class TestWindow extends ApplicationWindow {

        
    public TestWindow() {
            
    super(null);
        }

        
    protected Control createContents(Composite parent) {
            Text text 
    = new Text(parent,SWT.NONE);
            text.setText(
    "hello world");
            Text text1 
    = new Text(parent,SWT.NONE);
            text1.setText(
    "it's me");
            
    return parent;
        }

        
    public static void main(String args[]) {
            
    try {
                TestWindow window 
    = new TestWindow();
                window.setBlockOnOpen(
    true);
                window.open();
                Display.getCurrent().dispose();
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

    運(yùn)行,并沒有看到第二個(gè)Text,為什么?
    是否沒有設(shè)置text的Bounds?好設(shè)置一下
    import org.eclipse.jface.window.ApplicationWindow;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.graphics.Point;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Text;


    public class TestWindow extends ApplicationWindow {

        
    public TestWindow() {
            
    super(null);
        }

        
    protected Control createContents(Composite parent) {

            Text text 
    = new Text(parent, SWT.BORDER);
            text.setText(
    "hello world");
            text.setBounds(
    591128025);
            
            Text text_1 
    = new Text(parent, SWT.BORDER);
            text_1.setText(
    "it's me");
            text_1.setBounds(
    722218025);
            
    return parent;
        }

        
    public static void main(String args[]) {
            
    try {
                TestWindow window 
    = new TestWindow();
                window.setBlockOnOpen(
    true);
                window.open();
                Display.getCurrent().dispose();
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }

        
    private void createActions() {
        }

    }

    效果依舊,那是為什么呢?
    這是因?yàn)樵赾reateContents()方法中直接使用了參數(shù)中的parent,造成了布局(layout)的混亂,在只有一個(gè)的text的情況下看不出來,現(xiàn)在就看出來了。
    解決辦法:再構(gòu)造一個(gè)composite,在我們平時(shí)使用的時(shí)候記得一定要構(gòu)造一個(gè)自己的composite,設(shè)置自己的布局,不要直接使用參數(shù)中的composite
    import org.eclipse.jface.window.ApplicationWindow;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Text;


    public class TestWindow extends ApplicationWindow {

        
    public TestWindow() {
            
    super(null);
        }

        
    protected Control createContents(Composite parent) {
            Composite container 
    = new Composite(parent, SWT.NONE);

            Text text 
    = new Text(container, SWT.BORDER);
            text.setText(
    "hello world");
            text.setBounds(
    591128025);
            
            Text text_1 
    = new Text(container, SWT.BORDER);
            text_1.setText(
    "it's me");
            text_1.setBounds(
    722218025);
            
    return container;
        }

        
    public static void main(String args[]) {
            
    try {
                TestWindow window 
    = new TestWindow();
                window.setBlockOnOpen(
    true);
                window.open();
                Display.getCurrent().dispose();
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }

        
    private void createActions() {
        }

    }


    posted on 2007-08-07 09:10 dreamstone 閱讀(1413) 評論(0)  編輯  收藏 所屬分類: SWT和插件開發(fā)

    主站蜘蛛池模板: 久久成人免费电影| 精品四虎免费观看国产高清午夜| 久久久久久精品免费看SSS| 亚洲国产精品一区二区成人片国内 | 91在线老王精品免费播放| 久久夜色精品国产亚洲AV动态图| 99在线热播精品免费99热| 亚洲女同成av人片在线观看| 特级做A爰片毛片免费看无码 | 国产精品无码一区二区三区免费| 在线综合亚洲欧洲综合网站| 成人人免费夜夜视频观看| 亚洲国产精品18久久久久久 | 免费黄色app网站| 国产精品亚洲色婷婷99久久精品| 国产一区二区三区免费视频| 一区二区三区在线免费| 亚洲第一极品精品无码久久| 日韩人妻无码精品久久免费一| 亚洲一区二区影院| 女人被男人桶得好爽免费视频| 日本亚洲高清乱码中文在线观看| 亚洲一区二区三区免费| 可以免费观看的毛片| 亚洲国产成人在线视频| 国产在线观看免费完整版中文版| 黄页网站在线观看免费| 亚洲成AV人片在线观看ww| 国产成人精品免费视| 日韩亚洲人成在线综合| 国产亚洲婷婷香蕉久久精品 | 国产麻豆剧传媒精品国产免费| 日韩免费码中文在线观看| 亚洲AV无码专区亚洲AV伊甸园| 免费大片黄在线观看yw| 国产一区二区三区亚洲综合| 亚洲AV无码专区国产乱码电影| 黄页网站免费观看| 一个人看的免费观看日本视频www 一个人看的免费视频www在线高清动漫 | 亚洲福利在线播放| 亚洲午夜免费视频|