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

        }


    }
    主站蜘蛛池模板: 奇米影视亚洲春色| 亚洲成a人片在线看| 69视频在线观看高清免费| 亚洲一区二区三区在线播放| 亚洲AV无一区二区三区久久| 中文字幕一区二区三区免费视频| 国产极品粉嫩泬免费观看| 亚洲依依成人亚洲社区| 在线观看视频免费国语| 亚洲精品成a人在线观看☆| 在线视频免费观看www动漫| 亚洲AV成人一区二区三区观看 | 国产精品无码一区二区三区免费| 久久久久久久久亚洲| 免费人成激情视频在线观看冫| 亚洲精品tv久久久久久久久| 日本高清免费观看| 亚洲高清无在码在线电影不卡 | 精品熟女少妇aⅴ免费久久| 亚洲欧洲无码AV电影在线观看| 免费一区二区无码东京热| 亚洲电影国产一区| 亚洲免费福利视频| 国产亚洲精品影视在线| 国产精品无码素人福利免费| 女人裸身j部免费视频无遮挡| 久久久久亚洲?V成人无码| 免费91最新地址永久入口| 久久亚洲精品无码aⅴ大香| 国产精品69白浆在线观看免费| 亚洲熟妇无码av另类vr影视| 久久精品中文字幕免费| 亚洲国产精品日韩在线| 嫩草影院在线免费观看| 免费观看四虎精品成人| 亚洲精品成人网站在线观看| 777爽死你无码免费看一二区| 亚洲啪AV永久无码精品放毛片| www.亚洲色图.com| 爱丫爱丫影院在线观看免费| 亚洲福利视频网址|