Swing GUI 组件过于紧凑

发布于 2024-08-08 05:27:10 字数 333 浏览 4 评论 0原文

在 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 技术交流群。

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

发布评论

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

评论(6

坠似风落 2024-08-15 05:27:10

查看 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

疏忽 2024-08-15 05:27:10

您可以使用 MiGLayout 作为布局管理器。它允许各种自定义,包括边距/填充。

You could use MiGLayout as your layout manager. It allows all kinds of customizations, including margins/paddings.

甜尕妞 2024-08-15 05:27:10

通过使用 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).

野鹿林 2024-08-15 05:27:10

从 Java 1.6 swing 开始,出现了一个新的 GroupLayout 使此类工作变得更容易的经理。

例如有一个方法: setAutoCreateGaps()

...将两个组件添加到 SequentialGroup 中,两个组件之间会自动创建间隙...

例如:

alt text

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:

...you add two components to a SequentialGroup a gap between the two components is automatically be created...

For instance:

alt text

栀子花开つ 2024-08-15 05:27:10

您使用什么 LayoutManager ?添加边距非常简单,但这取决于所使用的特定布局管理器。

What LayoutManager are you using? Adding margins is quite easy, it depends however on the specific LayoutManager used.

浮世清欢 2024-08-15 05:27:10

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.

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