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

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

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

    DANCE WITH JAVA

    開發出高質量的系統

    常用鏈接

    統計

    積分與排名

    好友之家

    最新評論

    Jface的Hello world引出的問題

    Jface的hello World網上到處都是,但簡單的Hello world能引出很多需要注意的問題.
    首先大部分網上的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();
            }

        }

    }


    這個代碼是可以運行的,而且運行的結果也看不出什么問題。但看不出來并不代表沒有問題。下邊我們來讓問題顯現
    在createContents()函數中再加入一個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();
            }

        }

    }

    運行,并沒有看到第二個Text,為什么?
    是否沒有設置text的Bounds?好設置一下
    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() {
        }

    }

    效果依舊,那是為什么呢?
    這是因為在createContents()方法中直接使用了參數中的parent,造成了布局(layout)的混亂,在只有一個的text的情況下看不出來,現在就看出來了。
    解決辦法:再構造一個composite,在我們平時使用的時候記得一定要構造一個自己的composite,設置自己的布局,不要直接使用參數中的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 閱讀(1420) 評論(0)  編輯  收藏 所屬分類: SWT和插件開發

    主站蜘蛛池模板: 亚洲精品无码你懂的网站| 九一在线完整视频免费观看| 免费国产成人α片| 亚洲女久久久噜噜噜熟女| 一道本不卡免费视频| 久久久久亚洲精品男人的天堂| 色婷婷亚洲一区二区三区| 欧洲美熟女乱又伦免费视频| 亚洲日韩AV无码一区二区三区人| 天天看片天天爽_免费播放| 亚洲乱码中文字幕在线| 国产区卡一卡二卡三乱码免费| 精品久久久久久久久亚洲偷窥女厕| 国产jizzjizz免费视频| 一级中文字幕乱码免费| 亚洲国产精品无码中文字| 99热在线免费观看| 亚洲一区二区三区不卡在线播放| 毛片a级三毛片免费播放| 国产午夜亚洲精品不卡免下载 | 亚洲av中文无码乱人伦在线咪咕| 叮咚影视在线观看免费完整版| 久久噜噜噜久久亚洲va久| 91免费在线播放| 久久亚洲精品无码av| 亚洲精品tv久久久久| 久久国产精品萌白酱免费| youjizz亚洲| 亚洲精品无码永久在线观看 | 18亚洲男同志videos网站| 免费在线观看的网站| 免费在线观看一区| 亚洲国产精品久久66| 免费看片免费播放| 日本免费A级毛一片| 亚洲综合校园春色| 亚洲免费日韩无码系列| 四虎成年永久免费网站| 免费的黄色的网站| 亚洲欧洲视频在线观看| 亚洲精品视频在线看|