我想设置JFrame运行初始时在桌面上的不同位置显现,比如在窗口桌面的中央、窗口桌面的坐上方(这本来就是默认的)、在窗口的右上方等

解决方案 »

  1.   

    自己计算jframe 左上角的坐标、然后调用 jframe.setLocation(x,y);或者Point location = ……;
    jframe.setLocation(location);
    还可以使用 
    jframe.setBounds(10,10,111,111);
      

  2.   

    setBound··这个最为直接和简单··
      

  3.   

          //---------------------------设置窗口居中----------------------------------------------------------
            int windowWidth = frame.getWidth();                    //获得窗口宽
            int windowHeight = frame.getHeight();                  //获得窗口高
            Toolkit kit = Toolkit.getDefaultToolkit();             //定义工具包
            Dimension screenSize = kit.getScreenSize();            //获取屏幕的尺寸
            int screenWidth = screenSize.width;                    //获取屏幕的宽
            int screenHeight = screenSize.height;                  //获取屏幕的高
            frame.setLocation(screenWidth/2-windowWidth/2, screenHeight/2-windowHeight/2);//设置窗口居中显示
            //------------------------------------------------------------------------------------------------
     其他一样
      

  4.   

    居中不需要楼上那样,一个方法即可
    setLocationRelativeTo(null);
      

  5.   

    jframe.setBounds(x1,x2,x3,x4);
    x1,x2表示初始显示位置,x3,x4表示窗体大小!
      

  6.   

    设置它的起始位置是setLocation()方法,我一般用setBound(),把位置大小一起设置了