Thursday 15 January 2015

java - gridheight doesn't seem to work -



java - gridheight doesn't seem to work -

i trying utilize gridbaglayout, i've problem it. want create layout using 12 rows. first create 2 jpanels filling first 2 rows (with gridheight = 1). create 5 other jpanels fill other 10 rows (with gridheight = 2). bottom 5 jpanels gridheight = {2,4,6,8,10}, won't overlap or anything. problem this: all jpanels same size!

i fill both ways , not using anchors. if add together jpanel gridx = 1, gridy = 0 , gridheight = 2, have doubled height, what's deal here? have tell layout scheme total amount of rows going utilize beforehand? if how do that?

there several aspects gridbaglayout (gbl) missed first time users.

1) components placed within gbl initialize @ "preferred" size. jpanel, iirc, has preferred size of 1x1.

2) if want gbl cells resize according enclosing container, need give them weightx , weighty. 2 attributes say, give cell percentage of available area according ratio of weightx's , weighty's assigned. e.g. if have 2 cells , 1 has weightx = 1.0 , sec 1 given 2.0, first cell 1/2 wide sec (or sec 1 twice wide).

3) gbl takes alot of trial , error when first dive in, powerful, flexible, , reliable layout (especially compared nested layouts, blech)

java swing layout-manager gridbaglayout

No comments:

Post a Comment