【问题标题】:How to setVisible a JinternalFrame in the center of the JdesktopPane?如何在 JdesktopPane 的中心设置可见的 JinternalFrame?
【发布时间】:2012-04-20 06:06:11
【问题描述】:

实际上,我想在 JDesktopPane 的中心显示 JinternalFrame,我在 Jframes 中使用这种方法,但它不起作用:

Extraction ex=new Extraction();//Extraction is the name of the JintenalFrame jDesktopPane1.add(ex); ex.setLocationRelativeTo(this); ex.setVisible(true);

所以我问是否有另一种方法,以便我可以在 JdesktoPane 的中心显示 JinternalFrame。 谢谢

【问题讨论】:

  • “其实我想..” 我想与会拼写所有字母的人通信,例如“想要”。 下一个!

标签: java swing jframe jinternalframe


【解决方案1】:

试试类似的东西:

JDesktopPane mainPanel;
JInternalFrame jif_test = new JInternalFrame();

public void centerJIF(JInternalFrame jif) {
    Dimension desktopSize = mainPanel.getSize();
    Dimension jInternalFrameSize = jif.getSize();
    int width = (desktopSize.width - jInternalFrameSize.width) / 2;
    int height = (desktopSize.height - jInternalFrameSize.height) / 2;
    jif.setLocation(width, height);
    jif.setVisible(true);
}

centerJIF(jif_test);

【讨论】:

    【解决方案2】:

    javax.swing.JInternalFrame 缺少 java.awt.Window 中提供的方便的 setLocationRelativeTo(null) 实现,但您可以使用类似的方法。只需从桌面窗格的相应中心坐标中减去内部框架的宽度和高度的一半。在您对setLocation() 的调用中使用新坐标。

    如有必要,您还需要调整内部框架的尺寸。

    【讨论】:

      猜你喜欢
      • 2011-11-21
      • 2013-08-28
      • 2014-01-14
      • 2012-11-29
      • 2011-06-03
      • 2014-12-14
      • 2011-12-29
      • 2011-10-15
      • 2011-11-23
      相关资源
      最近更新 更多