Java GridBag 布局

发布于 2025-01-08 03:45:00 字数 161 浏览 3 评论 0原文

我在使用 GridBagLayout 时遇到问题,我似乎无法掌握它。 下面是我的 GUI 应该是什么样子的,我似乎无法让它工作。 主要问题是排列文本框和文本框。标签在右侧和左手边。

所需布局

I am having a problem using GridBagLayout, I cant seem to get a hang of it.
below is what my GUI should look like, I cant seem to get it working.
The main problem is lining the text boxes & labels at the right & left hand side.

Desired Layout

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

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

发布评论

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

评论(3

剪不断理还乱 2025-01-15 03:45:01

我将有一个使用 BorderLayout 的主 JPanel。

然后,我将有两个从属 JPanel,一个使用 BorderLayout.WEST 添加到主 JPanel,另一个使用 BorderLayout.EAST 添加到主 JPanel。

西边的 JPanel 将使用 GridBagLayout,4 列和 4 行。我会使用 Insets 来获得我想要的间距。

东JPanel将使用GridBagLayout,4列6行。再次,我将使用 Insets 来获得我想要的间距。

我会将按钮放在使用 FlowLayout 的 JPanel 中。我设置了 JPanel 的首选大小,以便按钮保持在同一行。然后我将按钮 JPanel 添加到东 JPanel 作为第 6 行。

I would have a main JPanel that uses the BorderLayout.

Then I would have two subordinate JPanels, one added to the main JPanel using BorderLayout.WEST, and the other added to the main JPanel using BorderLayout.EAST.

The west JPanel would use the GridBagLayout, 4 columns and 4 rows. I would use Insets to get the spacing that I want.

The east JPanel would use the GridBagLayout, 4 columns and 6 rows. Again, I would use Insets to get the spacing that I want.

I would put the buttons inside of a JPanel that uses FlowLayout. I'd set the preferred size of the JPanel so the buttons stay on the same row. Then I'd add the button JPanel to the east JPanel as the 6th row.

挖鼻大婶 2025-01-15 03:45:01

如果您使用的是 Eclipse,我建议使用 Window Builder Pro 将 UI 置于您想要的位置。您将能够看到可以使用 Gridbag 布局转动的所有“转盘”。

您可能需要尝试一下事物的锚定方式,以使标签按照您想要的方式排列。

If you are using eclipse, I'd suggest using Window Builder Pro to get the UI where you you want it. You'll be able to see all the 'dials' you can turn with Gridbag layout.

You'll probably need to play with how things are anchored to get the labels to line up how you want.

梦断已成空 2025-01-15 03:45:00

可能是嵌套布局。对于左上角和右侧的“控件组”,将它们全部交换为 JTable1 每个或使用 GroupLayout2

1) JTable

2) GroupLayout

GroupLayout

另请参阅

  1. 如何使用表
  2. Swing 组件可视化指南
  3. 如何使用 GroupLayout
  4. 布局管理器可视化指南
  5. 嵌套布局示例(下图)。

Probably a nested layout. For the 'groups of controls' on the top left and the right hand side, swap them all for a JTable1 each or use GroupLayout2.

1) JTable

2) GroupLayout

GroupLayout

See also

  1. How to Use Tables
  2. A Visual Guide to Swing Components
  3. How to Use GroupLayout
  4. A Visual Guide to Layout Managers.
  5. Nested Layout Example (image below).

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