swing:JPanel 与模式/非模式对话框?

发布于 2024-08-19 19:44:17 字数 232 浏览 4 评论 0原文

我想在库中实现一些功能,并将其用作我的应用程序的 GUI 构建块。我想我想将它实现为扩展 JPanel 的东西,这样它就可以作为组件嵌入到其他窗口中。

我是否有理由使用 JDialog 来代替?创建一个显示 JPanel 以及最少其他适当组件的 JDialog 有多容易? (例如,对于无模式对话框,只有边框/关闭框/等;对于模态对话框,相同+确定/取消)

I want to implement some functionality in a library and make it available as a GUI building block for my applications. I think I would like to implement it as something that extends a JPanel, so it can be embedded as a component in other windows.

Is there a reason I should use a JDialog instead? How easy is it to create a JDialog which displays a JPanel along with minimal other appropriate components? (e.g. just a border/closebox/etc for modeless dialog; for modal, the same + an OK/Cancel)

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

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

发布评论

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

评论(2

甜心 2024-08-26 19:44:17

如果您想要一个对话框,则应该扩展 JDialog,如果您只想要一个可以在其他 Windows 或框架中使用的面板,则应该扩展 JPanel。

是的,创建一个 JDialog 很容易,它只包含一个带有边框、关闭框和确定/取消(模式和非模式)的 JPanel。

查看如何创建对话框和< a href="http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html" rel="nofollow noreferrer">如何使用面板

You should extend JDialog only if you want a Dialog, and if you want just a Panel that you can use in other Windows or Frames you should extend JPanel.

Yes, it is easy to create an JDialog just containing a JPanel with a border, closebox and OK/Cancel, both modal and not modal.

Have a look at How to Make Dialogs and How to Use Panels

无声无音无过去 2024-08-26 19:44:17

我会将其设为 JPanel。这样,您可以在其他组件中重用它,或者如果您想将其作为独立运行,则可以将其放入 JFrame 中(通过调用 setContentPane)。您需要JDialog的唯一原因是如果您想让组件成为模态组件。

I would make it a JPanel. That way you could reuse it in other components or drop it into a JFrame (by calling setContentPane) if you want to run it as a standalone. The only reason for you to need a JDialog is if you want to make your component modal.

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