Java Swing - JLabel 中出现空格

发布于 2025-01-08 08:59:44 字数 205 浏览 5 评论 0原文

我有一个填充了标签的面板,一旦将一些标签添加到面板中,一切都很好。但是,当我使用 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:

enter image description here

Can anyone guide me on how to remove this excess whitespace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2025-01-15 08:59:44

当您从屏幕上已可见的容器中删除或添加组件时,必须对容器调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文