跨足多列使用GridBagLayout | JAVA 8

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

Span multiple columns with GridBagLayout | JAVA 8

问题

以下内容可以使用GridBagLayout实现吗?这样,我的标题栏将占据5列宽度,所有其他元素的宽度为1。

期望结果:

+-----------------------------------------------------------------+
|                       HEADLINE                       | content0 |
+----------+----------+----------+----------+----------+----------+
| content1 | content2 | content3 | content4 | content5 | content6 |
+----------+----------+----------+----------+----------+----------+

当前状态:

+-----------------------------------------------------------------+
|                       HEADLINE                       | content0 |
+------------------------------------------------------+----------+----------+----------+----------+----------+
| content1                                             | content2 | content3 | content4 | content5 | content6 |
+------------------------------------------------------+----------+----------+----------+----------+----------+

当我将gridwidth设置为5和1时:(请记得将gridx增加5个...)

+-----------------------------------------------------------------+
|       HEA| content0 |DLINE                                      |
+----------+----------+----------+----------+----------+----------+
| content1 | content2 | content3 | content4 | content5 | content6 |
+----------+----------+----------+----------+----------+----------+
英文:

Is the following feasible with a Gridbaglayout? So that my headline has a columns width of 5 and all other elements a width of 1.

Wanted result:

+-----------------------------------------------------------------+
|                       HEADLINE                       | content0 |
+----------+----------+----------+----------+----------+----------+
| content1 | content2 | content3 | content4 | content5 | content6 |
+----------+----------+----------+----------+----------+----------+

Current state:

+-----------------------------------------------------------------+
|                       HEADLINE                       | content0 |
+------------------------------------------------------+----------+----------+----------+----------+----------+
| content1                                             | content2 | content3 | content4 | content5 | content6 |
+------------------------------------------------------+----------+----------+----------+----------+----------+

When I set the gridwidth to 5 and 1: (remember to increase the gridx by 5...)

+-----------------------------------------------------------------+
|       HEA| content0 |DLINE                                      |
+----------+----------+----------+----------+----------+----------+
| content1 | content2 | content3 | content4 | content5 | content6 |
+----------+----------+----------+----------+----------+----------+

答案1

得分: 2

当然,你将GridBagConstraints中标题的gridwidth设置为5,而将其他内容的gridwidth设置为1。(由于使用了GridBagLayoutcontentN的大小可能会有所不同。)

英文:

Sure, you set the gridwidth of the GridBagConstraints for the headline to 5, and 1 for the others. (It being GridBagLayout, the sizes of contentN may vary.

huangapple
  • 本文由 发表于 2020年10月9日 21:39:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/64281254.html
匿名

发表评论

匿名网友

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

确定