如何使用Java的Swing GUI工具来实现这个设计?

huangapple go评论55阅读模式
英文:

How can I go about creating this design with Java's Swing GUI tools?

问题

这是我心中项目布局的草图:

(图片链接)

我尝试实现的方式是:

我将整个框架设置为边框布局,然后在水平方向上划分为两个面板,我们称它们为北面板和南面板。南面板是第一张图片中的第3个面板。

我还将北面板设置为边框布局,并在垂直方向上划分为两个面板。这些变成了第一张图片中的第1个面板和第2个面板。问题出现在我尝试调整窗口大小时。我希望这些面板能够成比例地缩放,以便面板之间的大小比例保持不变。但问题是,面板在调整大小时并没有按预期进行缩放,而是像这样相互移开了:

(图片链接)

有关创建所需设计的任何想法吗?我走在正确的道路上吗?还是有其他适合我需求的 Swing 布局更合适?

英文:

This is a mock up for what I have in mind as a layout for my project:

如何使用Java的Swing GUI工具来实现这个设计?

如何使用Java的Swing GUI工具来实现这个设计?

The way I tried to accomplish this is:

I set the entire frame to a border layout and then cut it horizontally with two panels, we'll call them north and south panels. The south panel is Panel 3 from the first picture.

I set the north panel to a border layout as well and cut it vertically with two panels. These become panel 1 and panel 2 in the first picture. The problem occurs when I try to resize the window. I would like the panels to scale proportionally to eachother so the size ratio's between the panels stay the same. The problem is, instead of resizing, the panels just move away from each other like so:

如何使用Java的Swing GUI工具来实现这个设计?

Any ideas for creating the desired design? Am I on the right track or is there another swing layout that is better suited to my needs?

答案1

得分: 2

> 我希望面板按比例缩放,以便面板之间的大小比例保持不变。

尝试使用水平 BoxLayout。我相信它会按比例分配额外的空间,直到组件的最大尺寸(如果有多余的空间)。

或者,如果这不起作用,您可以使用 GridBagLayout。您可以为添加到面板的每个组件使用 weightx 约束。这将控制为每个组件分配了多少额外的空间。

阅读 Swing 教程中关于布局管理器的部分,其中包含每种布局的工作示例。

英文:

> I would like the panels to scale proportionally to eachother so the size ratio's between the panels stay the same.

Try using a horizontal BoxLayout. I believe it will allocate extra space proportionally up to the components maximum size if extra space is available.

Or if that doesn't work you can use a GridBagLayout. You can use the weightx constraint for each component you add to the panel. This will control how much extra space is given to each component.

Read the section from the Swing tutorial on Layout Managers for working example of each.

huangapple
  • 本文由 发表于 2020年9月2日 09:23:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63697425.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定