我创建了大小为 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/