如何在Swing中获取JWindow的父容器? [英] How to get the parent container of a JWindow in Swing?
本文介绍了如何在Swing中获取JWindow的父容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JFrame
,并在初始化时从该帧调用JDialog
.在对话框中有一个JButton
,单击按钮时将打开一个新的JWindow
.
I have one JFrame
and calling a JDialog
from that frame while initializing. In the dialog have a JButton
, when clicking on the button a new JWindow
opens.
我可以在主框架中固定窗口的位置吗?如何从JWindow
扩展类访问父容器(扩展为JFrame
)?
Can I fix the position of window in the main frame? How to access the parent container (JFrame
extended) from JWindow
extended class?
推荐答案
Use SwingUtilities.getWindowAncestor, if inside the JWindow
class, refer it as this
, if no, simply put object inside:
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(myJWindow);
这篇关于如何在Swing中获取JWindow的父容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文