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

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

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

    泰仔在線

    java學習,心情日記,繽紛時刻
    posts - 100, comments - 34, trackbacks - 0, articles - 0

    SWT窗口居中

    Posted on 2009-02-26 22:21 泰仔在線 閱讀(1664) 評論(0)  編輯  收藏 所屬分類: Java 相關
    一、使用SWT本身的Display.getClientArea().width. height

            
    ////
            loginShell.setLocation(display.getClientArea().width / 2 - loginShell.getSize().x/2, display
                    .getClientArea().height 
    / 2 - loginShell.getSize().y/2);
            
    ////
    二、使用SWT本身的loginShell.getMonitor().getBounds() 與loginShell.getBounds()
            ////
            Monitor primary = loginShell.getMonitor();
            Rectangle bounds 
    = primary.getBounds();
            Rectangle rect 
    = loginShell.getBounds();
            
    int x = bounds.x + (bounds.width - rect.width) / 2;
            
    int y = bounds.y + (bounds.height - rect.height) / 2;
            
    if (x < 0)
                x 
    = 0;
            
    if (y < 0)
                y 
    = 0;
            loginShell.setLocation(x, y);
            
    ////
    原例:
    package demo;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    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 Login {

        
    /**
         * Launch the application
         * 
    @param args
         
    */

        
    public static void main(String[] args) {
            
    final Display display = Display.getDefault();
            
    final Shell loginShell = new Shell();
            loginShell.setSize(
    424222);
            loginShell.setText(
    "Login");
            
    ////
            loginShell.setLocation(display.getClientArea().width / 2 - loginShell.getSize().x/2, display
                    .getClientArea().height 
    / 2 - loginShell.getSize().y/2);
            
    ////
            loginShell.open();

            
    final Label label1 = new Label(loginShell, SWT.NONE);
            label1.setAlignment(SWT.RIGHT);
            label1.setText(
    "ユーザID:");
            label1.setBounds(
    101466512);

            
    final Label label2 = new Label(loginShell, SWT.NONE);
            label2.setAlignment(SWT.RIGHT);
            label2.setBounds(
    101816512);
            label2.setText(
    "パスワード:");

            
    final Text userName = new Text(loginShell, SWT.BORDER);
            userName.setBounds(
    1734210520);

            
    final Text password = new Text(loginShell, SWT.BORDER);
            password.setBounds(
    1737710520);

            
    final Button btnLogin = new Button(loginShell, SWT.NONE);
            btnLogin.addMouseListener(
    new MouseAdapter() {
                
    public void mouseDown(MouseEvent e) {
                    
    try {
                        MaterialUpload window 
    = new MaterialUpload();
                        loginShell.close();
                        window.open();
                    }
     catch (Exception ex) {
                        ex.printStackTrace();
                    }

                }

            }
    );
            btnLogin.setText(
    "ログイン");
            btnLogin.setBounds(
    1011305922);

            
    final Button btnClear = new Button(loginShell, SWT.NONE);
            btnClear.addMouseListener(
    new MouseAdapter() {
                
    public void mouseDown(MouseEvent arg0) {
                    userName.setText(
    "");
                    password.setText(
    "");
                }

            }
    );
            btnClear.setText(
    "クリア");
            btnClear.setBounds(
    1831305922);

            
    final Button btnClose = new Button(loginShell, SWT.NONE);
            btnClose.addMouseListener(
    new MouseAdapter() {
                
    public void mouseDown(MouseEvent arg0) {
                    loginShell.close();
                }

            }
    );
            btnClose.setBounds(
    2641305922);
            btnClose.setText(
    "閉じる");
            loginShell.layout();
            
    while (!loginShell.isDisposed()) {
                
    if (!display.readAndDispatch())
                    display.sleep();
            }

        }


    }
    主站蜘蛛池模板: 无码国产精品久久一区免费| 亚洲中文字幕无码永久在线| 中文字幕一区二区免费| 久久精品国产亚洲av天美18| 亚洲视频在线观看免费| 亚洲av无码乱码在线观看野外| 在线亚洲午夜片AV大片| 久久精品国产免费一区| 亚洲一区二区高清| 噜噜综合亚洲AV中文无码| 无码国产精品一区二区免费式直播 | 亚洲狠狠婷婷综合久久久久| 国产老女人精品免费视频| 国产精品久久久亚洲| 亚洲国产精品毛片av不卡在线| 亚洲一区二区三区丝袜| 日韩欧毛片免费视频| 亚洲 欧洲 视频 伦小说| 免费高清小黄站在线观看| 国产亚洲精品精品精品| 亚洲 国产 图片| 97人妻精品全国免费视频| 亚洲高清免费在线观看| 在线播放免费人成视频在线观看| 最新中文字幕电影免费观看| 亚洲精品乱码久久久久蜜桃| www.亚洲色图.com| 国偷自产一区二区免费视频| 亚洲一区二区三区深夜天堂 | 日本中文字幕免费高清视频| 最近免费中文字幕4| 国产成人 亚洲欧洲| 亚洲尤码不卡AV麻豆| 97在线观看永久免费视频| 精品亚洲视频在线| 亚洲高清国产AV拍精品青青草原| 亚洲午夜在线一区| 99久久久国产精品免费牛牛 | 18成禁人视频免费网站| 在线观看国产情趣免费视频| 午夜在线免费视频 |