views:

59

answers:

2

How to check for empty cells in gridbaglayout? e.g. there are 100 cells, only 10 filled with label or pictures?

+1  A: 

Well the GridBagLayout has a getConstraints(Component) method. So you could get all the components in the Container and then get the constraint for each component. The constraint will contain the gridX/gridY value which you could use to populate a 2D array. You may also not to consider the gridWidth/gridHeight values.

So the answer is yes you could derive all the information.

camickr
+1 : You can derive the values, even though there isn't a direct provision for it in the API.
bguiz
A: 

You could use table2gridbag to avoid producing empty cells in the first place. It's a console tool that takes an HTML table, describing the layout, and transforms it into suitable Java source code for configuring the GridbBaglayoutManager to produce an equivalent layout.

Simon