简体   繁体   English

根据JDialog调整JPanel的大小

[英]Resize a JPanel in line with a JDialog

I've got a JDialog which contains a series of JPanels in a CardLayout . 我有一个JDialog ,它在CardLayout包含一系列JPanels Some of these panels contain JTables which I would like to be resized in line with any resizing of the JDialog . 其中一些面板包含JTables ,我希望根据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 . 编辑: JDialog用作向导,因此在任何一次仅显示一个面板,因此使用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! 理想情况下,我想保留的是布局管理器,尽管如果是问题的根源,那么显然我会重新考虑!

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 您可以保留CardLayout,但需要执行以下操作:1.将JDialog的布局设置为BorderLayout,然后向JDialog添加新的JPanel( contentPanel
2. now set this contentPanel layout to be CardLayout 2.现在将此contentPanel布局设置为CardLayout
3. add your other panels to the cardlayout as required. 3.根据需要将其他面板添加到cardlayout中。
4. Also make sure off the layouts you use on each of the panels you're adding to the CardLayout. 4.还要确保要在要添加到CardLayout的每个面板上使用的布局。 By default JPanel uses FlowLayout, I think, and this is not ideal for a JTable. 我认为,默认情况下,JPanel使用FlowLayout,这对于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. 也可以尝试使用BoxLayout或BorderLayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM