简体   繁体   English

如何以编程方式调整BorderLayout中的组件的大小?

[英]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.

相关问题 如何从使用 BorderLayout 的 JFrame 中删除组件 - How do I remove component from JFrame that uses BorderLayout 如何在不使用BorderLayout的情况下将组件放在JPanel中居中? -Java - How do I center a Component in a JPanel without using BorderLayout? - Java 如何创建在Borderlayout北位置自动调整大小的组件 - How do I create a component that auto-sizes in the Borderlayout North Position 如何在Netbeans Matisse中使用BorderLayout - How do I use BorderLayout with Netbeans Matisse 如何使用 BorderLayout 创建一个框架并为每个空间分配一个组件? - How can I create a frame with a BorderLayout and assign each space a component? 如何使边框布局的.CENTER 中的组件占据所有中心空间并随应用程序调整大小? - How does one make a component in the .CENTER of a Borderlayout occupy all center space and resize with the app? BorderLayout — 替换 BorderLayout 组件 - BorderLayout — replacing BorderLayout component 如何消除BorderLayout.CENTER占用的差距? - How do I eliminating the gap that BorderLayout.CENTER is taking up? 我如何同时使用 BorderLayout 和 SpringLayout? - How do i use both BorderLayout and SpringLayout together? 如何在borderlayout北段放置两个Jpanels/Jbuttons? - How do I put two Jpanels/Jbuttons in the borderlayout north section?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM