在BorderLayout.CENTER中设置JPanel的最大大小 [英] set maximum size of JPanel inside BorderLayout.CENTER

查看:381
本文介绍了在BorderLayout.CENTER中设置JPanel的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BorderLayout.CENTER里面有一个JPanel

I have a JPanel inside BorderLayout.CENTER

JPanel有一个网格布局,我希望它用CENTER扩展它的宽度,但是高度必须停止在最大值并尽可能使用preferredSize。

The JPanel has a Grid Layout, and I want it to expand with the CENTER for its width, but the height must stop at a maximum and use the preferredSize when possible.

我有这个代码

JPanel wrapperCenterPanel = new JPanel(new FlowLayout());
wrapperCenterPanel.add(centerPanel);    
panel.add(wrapperCenterPanel, BorderLayout.CENTER);

centerPanel是我的面板(使用GridLayout),我用FlowLayout面板包装它,然后放入这是CENTER中的最后一个。

centerPanel is my panel (uses GridLayout), I'm wrapping it with a FlowLayout panel, and putting this last one in the CENTER.

现在尺寸是首选,但它已经修好了!如果需要,高度不会缩小,宽度也不会缩小。

Now the size is the preferred one, but it's fixed!! The height doesn't shrink if necessary, and neither does the width.

我该怎么做?

推荐答案

尝试使用BoxLayout作为包装器面板。 BoxLayout尊重组件的最大/最小和首选大小。

Try using a BoxLayout as the wrapper panel. A BoxLayout respects the maximum/minimum and preferred size of a component.

这篇关于在BorderLayout.CENTER中设置JPanel的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆