How to set "columnWeights" and "rowWeights" for a GridBagLayout in NetBeans?
Apologies if I'm missing something silly... but I'm experimenting with NetBean's WYSIWYG Swing GUI builder, and am having some issues with GridBagLayout.
When writing a Swing application from scratch, I'll typically establish the column and row weights in one fell swoop at the time I first declare the layout. Something like this:
final JPanel myContainer = new JPanel();
GridBagLayout gbl = new GridBagLayout();
gbl.columnWeights = new double[]{0.0f, 0.0f, 1.0f};
gbl.rowWeights = new double[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
myContainer.setLayout(gbl);
However, when using the NetBeans WYSIWYG builder, I haven't found a clean way to access my GridBayLayout's "columnWeights" and "rowWeights" member variables. How do developers 开发者_如何学Pythongo about doing this with the NetBeans builder?
Have a look at NetBeans 7, they've just overhauled the GridBagLayout Designer.
Wow, not a lot of NetBeans-love here on StackOverflow, compared to the "Eclipse" tag! At any rate, after spending a full day crawling through various discussion boards and talking with more experienced users... it's apparent that NetBeans' WYSIWYG Swing builder simply doesn't expose these two GridBagLayout attributes. Moreover, the GridBagLayout object is entirely encapsulated within an automatically-generated code block, so any custom code added there will be overwritten.
The closest thing to an "answer" is that rather than applying weight values to all columns or rows... you can instead set a column or row's weight by setting those values on any random component within each column or row.
In the case of my code snippet above... I had a bunch of small components on the left-hand side of the panel, and one really big component on the right that I wanted to fill all that space. Just setting "weightx" and "weighty" to "1.0" for that component, while keeping it at "0.0" for all the other components, achieved the same result.
精彩评论