开发者

Problems with my GridLayout

I have a GridLayout 2开发者_运维技巧 rows by 5 columns, and I want to make the height of the first row to something like 50, and the second row to 200. I know GridLayout creates equally-sized cells, so this didn't work out. I also tried splitting the two rows into two GridLayouts setting their desired heights and adding them to a FlowLayout, but the columns didn't align the way I wanted it to. My code went something like this:

row1.setSize(WIDTH, 50); //GridLayout
row2.setSize(WIDTH, 200); //GridLayout
panel.add(row1);
panel.add(row2); //panel is a FlowLayout

The columns aligning are very important and I can't seem to get this right.


I'd look into GridBagLayout. Although, almost everyone I've talked seems to dislike it. I like it, though.


You can't do this with a GridLayout.

You should be able to use either a GridBagLayout or a SpringLayout. Check out the Swing tutorial on Layout Managers for some examples to get you started.

Also you don't add individual rows to the layout. You need to add all 10 components individually to the same panel using whatever layout manager you choose.


Each cell in a GridLayout is exactly the same size, so you'll have to use a different layout manager, e.g. GridBagLayout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜