摆动布局-在保持零件尺寸的同时使用网格 [英] Swing layout - Using a grid while keeping component dimensions

查看:76
本文介绍了摆动布局-在保持零件尺寸的同时使用网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为应用程序创建一个登录栏,但我不知道如何组织一系列JLabel和JTextField,以使它们在水平网格中组织,而 调整组件大小以适合每个单元.我还想确保组件组的大小不会低于特定宽度.如何实现?

I'd like to make a login bar for an application and I can't figure out how to organize a series of JLabels and JTextFields such that they are organized in a horizontal grid without these same components being resized to fit each cell. I also want to make sure that the group of components isn't resized below a certain width. How can this be achieved?

谢谢大家的回答.稍后,我将看一下MigLayout和SpringLayout.由于时间限制,我将不得不使用Visual Editor并使用null布局.必须手动调整组件的放置和尺寸,但至少要保持放置状态.这是一张显示我想做什么的图片.

Thanks for the answers everyone. I'll have a look at MigLayout and SpringLayout later. Due to time constraints I'm going to have to make do with Visual Editor and use a null layout. The component placement and dimensions have to be adjusted by hand but at least they stay put. Here's a picture showing what I wanted to do.

栏http://img145.imageshack.us/img145/7356/bargw. png

推荐答案

使用 MigLayout 作为布局管理器,它非常灵活,可以很轻松地支持您的要求.您可以设置大小限制.如果您需要其他帮助,请使用Swing和MigLayout发布一些示例代码,其中显示了您要执行的操作,然后我将为您提供建议,告诉您如何执行您要实现的目标.

Use MigLayout as your layout manager, it's extremely flexible, and supports what you're asking quite easily. You can set size constraints. If you need any further help, post some example code using Swing and MigLayout which shows what you're trying to do, and then I'll advise you on how to do what you want to achieve.

您可能想要一些增加"的单元格来填充剩余的空间.通过在列之间插入推"(由[..]指定)以扩大间隙,可以使用列约束来实现.在这种情况下,您不需要任何占位符组件. (即[pref!] 10px [40px ::] push [pref!] 10px [40px ::])

You probably want some additional cells which 'grow' to fill the remaining space. This can be achieved with column constraints, by inserting 'push' between the columns (specified by [..]) to expand the gap. You don't need any placeholder components in this case. (i.e., [pref!]10px[40px::]push[pref!]10px[40px::])

这篇关于摆动布局-在保持零件尺寸的同时使用网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆