Zak*_*rah 1 java swing jframe jinternalframe
实际上我想在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.谢谢
尝试类似的东西:
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);
}
Run Code Online (Sandbox Code Playgroud)
和
centerJIF(jif_test);
Run Code Online (Sandbox Code Playgroud)
一个javax.swing.JInternalFrame缺乏方便setLocationRelativeTo(null)的发现实现java.awt.Window,但你可以使用类似的方法.只需从桌面窗格的相应中心坐标中减去内部框架宽度和高度的一半.使用通话中的新坐标setLocation().
如有必要,您还需要调整内部框架的尺寸.
| 归档时间: |
|
| 查看次数: |
9518 次 |
| 最近记录: |