根据 JDialog 调整 JPanel 的大小

发布于 2024-07-07 21:26:46 字数 408 浏览 9 评论 0原文

我有一个 JDialog,其中包含 CardLayout 中的一系列 JPanels。 其中一些面板包含 JTables,我希望根据 JDialog 的任何大小调整来调整其大小。 我不知道如何实现这一点,任何帮助将不胜感激。

目前,这些表只是保持当前的大小并且没有缩放。 我确信它很简单,但我无法找到所需的确切方法。

提前谢谢了。 如果需要,我将提供更多信息。

编辑:JDialog 用作向导,因此任何时候仅显示一个面板,因此使用 CardLayout。 理想情况下,我希望保留这是布局管理器,尽管如果它是问题的根源,那么显然我会重新考虑!

I've got a JDialog which contains a series of JPanels in a CardLayout. Some of these panels contain JTables which I would like to be resized in line with any resizing of the JDialog. I am not sure how to achieve this and any help would be greatly appreciated.

At present the tables simply remain their current size and do not scale. I'm sure its something simple but I'm having trouble locating the exact approach needed.

Many thanks in advance. I will provide any more information if required.

edit: The JDialog is used as a wizard, so only one of the panels is being displayed at any one time, hence the use of CardLayout. I would ideally like to keep this is layout manager, although if it is the source of the problems then obviously I would rethink!

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

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

发布评论

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

评论(1

醉殇 2024-07-14 21:26:46

您可以保留 CardLayout,但需要执行以下操作:
1. 将 JDialog 的布局设置为 BorderLayout,并添加一个新的 JPanel (contentPanel) 到 JDialog
2. 现在将此 contentPanel 布局设置为 CardLayout
3. 根据需要将其他面板添加到卡片布局中。
4. 还要确保关闭您要添加到 CardLayout 的每个面板上使用的布局。 我认为,默认情况下 JPanel 使用 FlowLayout,这对于 JTable 来说并不理想。 因此,您可能还需要尝试一下包含表格的面板的布局; 也可以尝试 BoxLayout 或 BorderLayout。

You can keep the CardLayout, but you need to do the following:
1. set the layout of your JDialog to BorderLayout, and add a new JPanel (contentPanel) to the JDialog
2. now set this contentPanel layout to be CardLayout
3. add your other panels to the cardlayout as required.
4. Also make sure off the layouts you use on each of the panels you're adding to the CardLayout. By default JPanel uses FlowLayout, I think, and this is not ideal for a JTable. So you might need to play around with the layout of the panel containing the table as well; try out BoxLayout or BorderLayout for that as well.

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