// set the frame on the center of bildschirm
 private static void setFrameCenter(Frame f, boolean flag) {
   // f.getToolkit();
   //	Dimension screen=f.getToolkit().getDefaultToolkit().getScreenSize();//获取屏幕尺寸对象
   Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸对象
   Dimension myframe = f.getSize(); // 获取当前窗体的尺寸对象
   int w = (screen.width - myframe.width) / 2; // 水平位置
   int h = (screen.height - myframe.width) / 2; // 垂直位置
   f.setLocation(w, h);
   f.setResizable(flag);
 }
Exemple #2
0
 /**
  * Centre the dialog box in the frame. This must be called after the size has been established,
  * i.e. after the buttons etc. are arranged and pack() is called
  */
 public void centreInFrame() {
   Dimension frame_size = parent.getSize();
   Point frame_location = parent.getLocation();
   int centre_x = frame_location.x + frame_size.width / 2;
   int centre_y = frame_location.y + frame_size.height / 2;
   ;
   int xloc = centre_x - this.getSize().width / 2;
   int yloc = centre_y - this.getSize().height / 2;
   this.setLocation(new Point(xloc, yloc));
   this.requestFocus();
 }