[英]How do I programatically resize a component in a BorderLayout?
I have a JPanel that is located at the BorderLayout.SOUTH position of a parent JPanel. 我有一个JPanel,位于父JPanel的BorderLayout.SOUTH位置。 I would like to programatically change the height of this child JPanel.
我想以编程方式改变这个孩子JPanel的高度。
I am calling childPanel.setPreferredSize(new Dimension(getWidth(), newHeight));
我正在调用
childPanel.setPreferredSize(new Dimension(getWidth(), newHeight));
, but it has no effect. ,但它没有效果。 (I have tried setting the Maximum and Minimum sizes as well.)
(我也尝试过设置最大和最小尺寸。)
What (probably very simple thing) am I missing? 我错过了什么(可能非常简单的事情)?
After changing the preferred size, you need to call revalidate() on that childPanel. 更改首选大小后,您需要在该childPanel上调用revalidate() 。
You may want to read this Oracle Tutorial on LayoutManagers 您可能希望阅读有关LayoutManagers的Oracle Tutorial
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.