如何打开JDesktopPane中心的JInternalFrame? [英] How do I open a JInternalFrame centered in a JDesktopPane?
本文介绍了如何打开JDesktopPane中心的JInternalFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 JDesktopPane
中添加了一堆 JInternalFrame
,因为用户选择通过以下方式打开各种功能菜单。但我希望内部框架在桌面窗格中心打开,而不是左上角,它们似乎是默认的。
I am adding a bunch of JInternalFrame
s into a JDesktopPane
, as the user selects to open various features through the menus. But I would like the internal frames to open centered in the desktop pane, as opposed to the upper left, where they seem to default.
如何指定JInternalFrames打开中心,或者在打开后将它们移动到中心?
How can I specify that the JInternalFrames open centered, or move them to the center after opening?
jDesktopPane.add(jInternalFrame); // jInternalFrame is not centered!
推荐答案
供参考,这是我使用的解决方案,基于关于dogbane的建议:
For reference, here is the solution I used, based on dogbane's advice:
Dimension desktopSize = desktopPane.getSize();
Dimension jInternalFrameSize = jInternalFrame.getSize();
jInternalFrame.setLocation((desktopSize.width - jInternalFrameSize.width)/2,
(desktopSize.height- jInternalFrameSize.height)/2);
这篇关于如何打开JDesktopPane中心的JInternalFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文