[英]How to get the parent container of a JWindow in Swing?
I have one JFrame
and calling a JDialog
from that frame while initializing. 我有一个
JFrame
并在初始化时从该帧调用JDialog
。 In the dialog have a JButton
, when clicking on the button a new JWindow
opens. 在对话框中有一个
JButton
,单击按钮时将打开一个新的JWindow
。
Can I fix the position of window in the main frame? 我可以固定窗户在主机架上的位置吗? How to access the parent container (
JFrame
extended) from JWindow
extended class? 如何从
JWindow
扩展类访问父容器(扩展了JFrame
)?
Use SwingUtilities.getWindowAncestor , if inside the JWindow
class, refer it as this
, if no, simply put object inside: 如果在
JWindow
类中,请使用SwingUtilities.getWindowAncestor ,如果不是,则将其引用为this
,只需将对象放入其中:
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(myJWindow);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.