Swing GUI 组件过于紧凑
在 Java Swing 应用程序中,我觉得所有组件都包装得太紧密了。
在 QT 中,我们可以指定布局的填充和边距。
摇摆有类似的东西吗?
替代文本 http://img12.yfrog.com/img12/9612/screenshotscreenerconfi.png< /a>
这是我的应用程序的屏幕截图,我觉得太紧了(是吗?你觉得怎么样?
谢谢。
In the Java Swing app I made it seems to me that all the component are too tightly packed.
In QT one can specify padding and margins for the layout.
Is there something similar for swing?
alt text http://img12.yfrog.com/img12/9612/screenshotscreenerconfi.png
Here is a screen shot of my application that I thing is too tight (is it? what do you think?.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
查看 GridBagLayoutManager。它是最复杂的布局管理器,但一切都可以用它来完成。
它使用具有插入的 GridBagConstraintObject属性,它指定顶部、底部、左侧和右侧组件的分隔。
示例:GridBagConstraintObject.insets.left=20
Take a look to the GridBagLayoutManager. Its the most compex layout manager but everything can be acomplished whith it.
It uses the GridBagConstraintObject which has the inset property, it specifies the separation to the top, bottom, left and right components.
example: GridBagConstraintObject.insets.left=20
您可以使用 MiGLayout 作为布局管理器。它允许各种自定义,包括边距/填充。
You could use MiGLayout as your layout manager. It allows all kinds of customizations, including margins/paddings.
通过使用 DesignGridLayout 只需几行代码,您就可以为上面的示例实现更好的布局代码(布局中每行一个)。 DesignGridLayout 将自动使用运行时平台的正确间距。
此外,我强烈建议您不要在表单中使用 TitledBorders,因为它会阻止任何 LayoutManager(尽管可能很先进)自动正确对齐不同组中的各种组件。相反,您可以将 JLabel 与 JSeparator 一起使用(DesignGridLayout 中有示例,但这适用于任何其他 LayoutManager)。
You could achieve a much better layout for the example above by using DesignGridLayout in just a couple of lines of code (one per row in your layout). DesignGridLayout will automatically use the correct spacing for the runtime platform.
besides I would highly suggest that you DON'T use TitledBorders in your form because it prevents ANY LayoutManager (as advanced as it may be) from automatically aligning correctly the various components across different groups. Instead you could use a JLabel with a JSeparator (there are examples in DesignGridLayout, but this works with any other LayoutManager).
从 Java 1.6 swing 开始,出现了一个新的 GroupLayout 使此类工作变得更容易的经理。
例如有一个方法: setAutoCreateGaps() :
例如:
Since Java 1.6 swing there is a new GroupLayout manager that make this kind of works easier.
For instance there is a method: setAutoCreateGaps() that:
For instance:
您使用什么 LayoutManager ?添加边距非常简单,但这取决于所使用的特定布局管理器。
What LayoutManager are you using? Adding margins is quite easy, it depends however on the specific LayoutManager used.
FormLayout 是另一个很好的布局管理器。使用像 JFormDesigner 这样的优秀 GUI 编辑器,它使 GUI 构建变得足够简单。在大多数情况下,JFormDesigner 实际上会自动添加足够的填充。我不得不建议不要使用 GridBagLayout。它的工作还不错,但是非常复杂,这使得它很难使用和维护。
FormLayout is another good layout manager. With a good GUI editor like JFormDesigner it makes GUI building easy enough. JFormDesigner actually automatically adds sufficient padding in most cases. I have to recommend against using GridBagLayout. It does the job alright, but is very complex which makes it difficult to use and maintain.