3

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?

razshan
  • 1,128
  • 12
  • 41
  • 59

1 Answers1

5

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045