如何在JAVA上相应地操作GridLayout设置?
我有一个 setLayout(new GridLayout(5,5,3,3));
5 行和 5 列。在第一行我想要一个大行。您知道如何在 Excel 中合并单元格。所以我只想合并第一行的 5 列。我将 JLabel 放在第一行,这非常烦人,因为我需要为每个网格单元设置多个 JLabel 并确保间距效果良好。
有没有办法在 GridLayout 上做到这一点?或者我严格遵守 5 行 5 列?
I have a setLayout(new GridLayout(5,5,3,3));
5 rows and 5 columns. On the first row I want one big row. You know how in excel, where you would merge cells. So I just want to merge the 5 columns only on the first row. I am putting a JLabel on the first row, and its very annoying that I need to have multiple JLabels for each grid cell and make sure spacing works out well.
Is there a way to do this on GridLayout? Or I am stuck with 5 rows and 5 col strictly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GridBagLayout
可以做这个。或者,您可以使用嵌套布局:将第一行添加到BorderLayout
和剩余的GridLayout
到CENTER
。另请参阅布局管理器可视化指南。附录:MiGLayout 在这种情况下也非常值得一看。 Web Start 演示特别吸引人,并且有关合并和拆分单元格<的手册部分/a> 可能有用。
GridBagLayout
can do this. Alternatively, you can use nested layouts: add the first row to theNORTH
ofBorderLayout
and remainingGridLayout
to theCENTER
. See also A Visual Guide to Layout Managers.Addendum: MiGLayout is also well worth a look in this context. The Web Start demo is particularly appealing, and the manual section on Merging and Splitting Cells may be useful.