java - 如何在java swing中自动扩展框架的高度

标签 java swing jframe

我创建了大小为 500,500 的小框架,在我的框架中我还添加了面板,我动态添加了标签和文本框,我在面板中添加了 10 个标签,它显示正确,但我将添加另外 5 个标签和文本框继续上面添加的标签意味着隐藏 5 个标签和文本框之后的内容,那么如何自动扩展框架高度

最佳答案

调用.pack()方法应该可以解决问题:

public void pack()

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. The resulting width and height of the window are automatically enlarged if either of dimensions is less than the minimum size as specified by the previous call to the setMinimumSize method. If the window and/or its owner are not displayable yet, both of them are made displayable before calculating the preferred size. The Window is validated after its size is being calculated.

关于java - 如何在java swing中自动扩展框架的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823407/

相关文章:

Java-使一种特定颜色透明

java - 按内部数组的字段之一对多维数组进行排序

java - 使用 ObjectInputStream 发送可序列化对象的问题

java - 如何使用 JGoodies 绑定(bind) JTable 中的 boolean 值

Java GUI 面板

java - 自定义绘制的 JPanel 不会出现在 JFrame 中

java - 初始化列表的构造函数时出现 StackOverFlowError

java - Spring 数据 REST : custom query for MongoDB repository

Java Swing 变量不递增

java - JFrame、JPanel、paintComponent 如何