如何使 BoxLayout.Y_AXIS 的每个 TextField 都有自己的宽度?

发布于 2024-12-05 18:18:29 字数 307 浏览 3 评论 0原文

TextFields ,四个,包含在布局为 BoxLayout(BoxLayout.Y_AXIS)Container 中。我希望每个 TextFields 都有自己的宽度。我尝试了 setPreferredWsetColumnsTextFields 的大小都相同,占据了所有剩余行的宽度。

那么如何让每个或某些TextFields在视觉上有自己的宽度呢?

There are TextFields , four , contained into a Container whose Layout is BoxLayout(BoxLayout.Y_AXIS). I want each of these TextFields to have their own width. I tried setPreferredW , also setColumns but the TextFields are all the same size which is occupying all the remaining row's width.

So how to make each or some TextFields have their own width visually ?

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

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

发布评论

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

评论(2

欲拥i 2024-12-12 18:18:29

BoxLayout 始终拉伸相反轴上的组件,因此文本字段将始终拉伸,无论其首选W如何(除非您知道自己在做什么,否则您绝不能弄乱该值的另一​​个原因......)。

解决方案很简单,将文本字段嵌套在多个 FlowLayout/BoxLayoutX 容器中,并将容器一一添加到盒子布局 Y 中。每个容器将占据 Y 轴容器的整个宽度,但其中的文本字段不会占用升起所有空间。

BoxLayout always stretches components on the opposite AXIS so the text fields will always stretch regardless of their preferredW (another reason why you must never mess with that value unless you know what you are doing...).

The solution is simple, nest the text fields in multiple FlowLayout/BoxLayoutX containers and add the containers one by one to the box layout Y. The containers will each occupy the full width of the Y AXIS container but the text fields within won't take up all the space.

凹づ凸ル 2024-12-12 18:18:29

我找到了解决方案:我派生了 TextField 类,并在构造函数中设置了首选宽度值。

PS:我没有调用 super();

I found the solution : I derived the TextField class and in the constructor I set the preferred width value.

PS : I did not call super();

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