【问题标题】:How to get the parent container of a JWindow in Swing?如何在 Swing 中获取 JWindow 的父容器?
【发布时间】:2015-05-08 11:28:50
【问题描述】:

我有一个JFrame 并在初始化时从该框架调用JDialog。在对话框中有一个JButton,单击按钮时会打开一个新的JWindow

我可以固定窗口在主框架中的位置吗?如何从JWindow扩展类访问父容器(JFrame扩展)?

【问题讨论】:

  • 请在您的问题中添加相关代码
  • 根据你想要做什么,你也许可以使用JDialog#setLocationRelativeTo并将JButton的引用传递给它

标签: java swing jframe jwindow


【解决方案1】:

使用SwingUtilities.getWindowAncestor,如果在JWindow类中,则将其称为this,如果没有,只需将对象放入:

JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);

JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(myJWindow);

【讨论】:

  • 我可以在第一帧修复窗口吗?
猜你喜欢
  • 2016-03-23
  • 1970-01-01
  • 2011-05-18
  • 2013-01-14
  • 1970-01-01
  • 2015-07-16
  • 2012-06-03
  • 2018-11-06
  • 1970-01-01
相关资源
最近更新 更多