我应该使用哪种java swing布局 [英] Which java swing layout should I use

查看:209
本文介绍了我应该使用哪种java swing布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建此框架:

我应该使用哪种布局?我正在考虑框或网格布局,但右边的菜单将是一个问题。

Which layout should I use? I am thinking about box or grid layout but then menu on the right will be a problem.

推荐答案

有很多重复在你的代码中。我会分解每个部分并将其作为一个单独的组件,并专注于它的个别布局需求。

There is a lot of repetition in your code. I would break down each section and make it a separate component and focus on it's individual layout needs.

在主屏幕中,您有4个主要区域(菜单除外)。

In you main screen you have 4 main areas (excluding the menu).

我会使用类似 GridBagLayout 来布局这4个部分。这使得每个部分都能够增长到所需的高度,而不会影响其他部分。您还可以根据需要为每个部分提供单独的增长提示。

I would use something like GridBagLayout to layout these 4 sections. This allows each section the ability to grow to it's required height, without effecting the others. You can also supply individual growth hints to each section as you see fit.

第一部分是 JLabel ,所以它非常简单

The first section is a JLabel, so it's pretty simple

此部分基本上是三个标签,对齐略有不同。我仍然会使用 GridBagLayout ,因为它提供了允许单个单元格对齐的最大灵活性,同时允许您提供大小调整提示(例如,我可能会将时间排在屏幕尺寸更改时的宽度。)

This section is basially three labels with slightly different alignments. I would still use a GridBagLayout as it provides the greatest flexibility to allow for individual cell alignment, while allowing you to provide sizing hints (for example, I might make the time row in width as the screen size is changed).

这部分有点复杂。基本上,它是左右相同的组件,有一些聪明的属性,你可以改变标签的位置而不会出现太多问题。

This section is a little more complicated. Basically, it's the same component on the left and right, with some clever properties, you would be able to change the position of the labels without to much of an issue.

可以使用 GridLayout 布置单个点/标签。我可能会谨慎行事并使用 GridBagLayout ,因为这样可以使标签的大小与点不同

The individual dots/labels could be laid out using a GridLayout. I might err on the side of caution and use a GridBagLayout, as it would allow the labels to be different sizes to the dots

然后我会使用类似 GridLayout 的东西将每一面放在一个组件上(然后放在主屏幕上)

I would then use something like a GridLayout to place each side onto a component (which would then be placed on the main screen)

同样,这个简单的镜像相同的组件。我只想创建一个可以通过属性调整的单个组件来更改对齐。

Again, this simple the same component mirrored. I would simply create a single component that could be adjusted via a property to change the alignment.

然后我只需使用 GridBagLayout 根据需要布置每个标签。我这样做是因为它允许每一行拥有它自己的高度。

I would then simply use a GridBagLayout to lay out each label as required. I'd do it this way because it allows each row the ability to have it's own height.

我还有15年的空手道经验。我能为你工作吗?

I also have 15 years referring experience in Karate. Can I come work for you?

这篇关于我应该使用哪种java swing布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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