英文:
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。(由于使用了GridBagLayout
,contentN
的大小可能会有所不同。)
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论