How to position the form in the center screen?

后端 未结 9 1860
小鲜肉
小鲜肉 2021-01-30 05:05

I\'m a .Net developer but somehow I was task to create a simple application in java for some extra reason. I was able to create that application but my problem is how can i cent

相关标签:
9条回答
  • 2021-01-30 05:36

    Try using this:

    this.setBounds(x,y,w,h);
    
    0 讨论(0)
  • 2021-01-30 05:38

    If you use NetBeans IDE right click form then

    Properties ->Code -> check out Generate Center

    0 讨论(0)
  • 2021-01-30 05:40

    i hope this will be helpful.

    put this on the top of source code :

    import java.awt.Toolkit;
    

    and then write this code :

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        int lebar = this.getWidth()/2;
        int tinggi = this.getHeight()/2;
        int x = (Toolkit.getDefaultToolkit().getScreenSize().width/2)-lebar;
        int y = (Toolkit.getDefaultToolkit().getScreenSize().height/2)-tinggi;
        this.setLocation(x, y);
    }
    

    good luck :)

    0 讨论(0)
提交回复
热议问题