« Return to Thread: GridLayout issues

GridLayout issues

by Russell Markus-2 :: Rate this Message:

Reply to Author | View in Thread

I am trying to implement a grid of panels which are placed into a GridLayout container.  My desire is to have the panels arranged in a fixed size matrix, 5 rows of 7 columns.  Not all "cells" will be populated, there will be unused ones in the first row and the last row.  Think of a calendar (this is the actual application).

My code is similar to:

JPanel matrix = new JPanel();
matrix.setLayout(new GridLayout(5, 7, 2, 2));

for (int i=0; i<unusedCnt; i++)
        matrix.add(new CellPanel(-1, invisible));
for (int i=1; i<=numDays; i++)
        matrix.add(new CellPanel(i, visible));

The CellPanel() is an extension to a JPanel which is working correctly.  The first param is the displayed title, and the second is whether or not the panel is visible.

My problem is that sometimes the display has 6 rows of 6 columns instead of five rows of seven columns.  Is there any way to force the correct number of columns?  I thought that declaring the GridLayout as I did would do the job.

Thanks!

Russell Markus

 « Return to Thread: GridLayout issues

LightInTheBox - Buy quality products at wholesale price!