如何在JAVA上相应地操作GridLayout设置?

发布于 2024-10-02 08:26:32 字数 220 浏览 10 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七月上 2024-10-09 08:26:32

GridBagLayout 可以做这个。或者,您可以使用嵌套布局:将第一行添加到 BorderLayout 和剩余的 GridLayoutCENTER。另请参阅布局管理器可视化指南

附录:MiGLayout 在这种情况下也非常值得一看。 Web Start 演示特别吸引人,并且有关合并和拆分单元格<的手册部分/a> 可能有用。

GridBagLayout can do this. Alternatively, you can use nested layouts: add the first row to the NORTH of BorderLayout and remaining GridLayout to the CENTER. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文