根据 JDialog 调整 JPanel 的大小
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以保留 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.