How to check for empty cells in Gridbaglayout?
How to check for empty cells in gridbaglayout? e.g. there ar开发者_运维技巧e 100 cells, only 10 filled with label or pictures?
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.
You can 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.
精彩评论