Does anyone know how to change the width of a panel? I tried using:
JPanel panel = new JPanel(); panel.setPreferredSize( new Dimension( 15, 15 ) );
however, this does not seem to change the dimension of my panel. I'm not sure if this makes any difference, but this panel is in a GridLayout. Perhaps I should be asking how do I change the dimension of the GridLayout? I have 3 rows and I would like the 1 row to be narrower than the last 2 rows.
Check the GridLayout api to see (in the first paragraph) that the grid is made so all cells are the same size. If you want a component to be shown at it's preferred size, like (15,15), add it to a JPanel and add the JPanel to the GridLayout. The JPanel will expand to fill the gird cell and allow the component to be shown at it's preferred size.
For a row of different size you'll have to try something else. Nested layouts would be a good starting place...