Java Swing:JInternalFrame:需要弹出对话框

发布于 2024-08-10 03:08:03 字数 262 浏览 1 评论 0原文

我有一个 JInternalFrame 窗口,需要在按下 JButton 时弹出一个模式对话框。起初,我尝试使用 JDialog,但我发现 JDialog 构造函数需要:

  1. JFrame
  2. boolean modal

我尝试将 JInternalFrame 传递给它,但类型不匹配。

我应该将 JDialog 与 JInternalFrame 一起使用吗?如果我不指定所有者(即传递 null)怎么办?这有什么问题吗?

I have a JInternalFrame window that needs to popup a modal dialog box when a JButton is pressed. At first, I tried using JDialog, but I found that JDialog constructor needs:

  1. JFrame
  2. boolean modal

I tried passing JInternalFrame to it, but the type didn't match.

Should I use JDialog with JInternalFrame? What if I dont specify the owner (i.e. passing a null)? Is there anything wrong with that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2024-08-17 03:08:03
SwingUtilities.getAncestorOfClass(Window.class, myButton)

上述方法将返回包含您的按钮的窗口。
一旦你拥有它,你可以将它传递给对话框的构造函数:)

编辑1:
我猜错了这个问题。你怎么能有一个JinternalFrame作为最上面的窗口?

编辑2:
另外,如果您将 null 传递给 Jdialog 构造函数,那么默认情况下它会使用共享所有者,即 SwingUtilities.getSharedOwnerFrame()

SwingUtilities.getAncestorOfClass(Window.class, myButton)

The abvove method will return the Window that contains your button.
Once you have it you can pass it to the constructor of the dialog :)

EDIT1:
I misread the question I guess. How can you have a JinternalFrame as the topmost window??

EDIT2:
Also if you pass null to Jdialog constrcutor then by default it uses a shared owner i.e SwingUtilities.getSharedOwnerFrame()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文