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

        }


    }
    主站蜘蛛池模板: 女人与禽交视频免费看| 99热免费在线观看| 国产一区二区三区在线免费观看| 无遮挡国产高潮视频免费观看| 你懂的免费在线观看| 亚洲欧洲自拍拍偷精品 美利坚 | 亚洲男人的天堂一区二区| 国产AV日韩A∨亚洲AV电影 | 成人免费777777被爆出| 最新免费jlzzjlzz在线播放| 亚洲另类激情综合偷自拍图| 三年片免费高清版| 亚洲国产精品无码久久久不卡| 免费在线看黄网站| 久久精品国产亚洲av高清漫画 | 婷婷亚洲综合五月天小说| 一级成人a毛片免费播放| 亚洲自偷自偷精品| 国产精品久久久久免费a∨| 亚洲av成人无码网站…| 亚洲精品无码成人片在线观看 | 在人线av无码免费高潮喷水| 亚洲AV无码成人网站在线观看| 免费少妇a级毛片人成网| 中文在线日本免费永久18近| 亚洲邪恶天堂影院在线观看| 免费精品国产日韩热久久| 午夜亚洲WWW湿好爽| 国产专区一va亚洲v天堂| 亚洲av无码片在线播放| 9420免费高清在线视频| 亚洲熟妇成人精品一区| 亚洲一本大道无码av天堂| 麻豆高清免费国产一区| 亚洲av中文无码乱人伦在线观看| 亚洲一区精品伊人久久伊人| 欧洲精品99毛片免费高清观看| 亚洲国产精品成人午夜在线观看| 亚洲综合伊人久久大杳蕉| 91免费资源网站入口| 一区二区视频免费观看|