Java Swing - JLabel 中出现空格
我有一个填充了标签的面板,一旦将一些标签添加到面板中,一切都很好。但是,当我使用 panel.removeAll();
删除面板中的所有内容并添加更多标签后,会出现如下图所示的空白:
谁能指导我如何删除多余的空白?
I have a panel that is populated with labels, and once some are added to the panel, all is well. However, after i remove everything in the panel with panel.removeAll();
and add some more labels, this whitespace appears that is shown in the image below:
Can anyone guide me on how to remove this excess whitespace?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您从屏幕上已可见的容器中删除或添加组件时,必须对容器调用
validate()
来修复布局。在此之前,屏幕上的外观是不确定的,而且通常很糟糕。When you remove or add components from a container that's already visible onscreen, you must call
validate()
on the container to get the layout fixed up. Until you do, the appearance onscreen is undefined, and usually bad.