gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:30:11 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com