弹出窗口出现在JOptionPane.show...Dialog(Component parentComponent)方法中指定的parentComponent的位置的中央。如果你要控制弹出框的位置,就要控制parentComponent的位置。(比方说有一个frame要在其上方弹出窗口,就不要直接把frame作为parentFrame,而先生成一个size为0,0的jwindow,将jwindow setLocation到frame上方,然后以jwindow作为parentComponent调用JOptionPane.show...Dialog())

解决方案 »

  1.   

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = this.getSize();
    if (frameSize.height > screenSize.height)
    {
       frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width)
    {
      frameSize.width = screenSize.width;
    }
    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    this.setVisible(true);
      

  2.   

    csdn出错!!!
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     Dimension frameSize = this.getSize();
     if (frameSize.height > screenSize.height)
    {
     frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width)
    {
    frameSize.width = screenSize.width;
    }
    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    this.setVisible(true);
      

  3.   

    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);之类就可以了。