Hi!
I have a form (frame) with a few panels in JTabbedPane on it. Frame has a BorderLayout as tabbed pane will occupy whole form. But each panel should have a GridBagLayout as each will contain buttons, labels, text fields and text areas.
Here is the current code I use to set up layouts on all panels:
// adds a component to a panel
private void addComponent(JPanel panel, Component component, int row, int column, int width, int height, GridBagLayout gbl, GridBagConstraints gbc)
{
gbc.gridx = column;
gbc.gridy = row;
gbc.gridwidth = width;
gbc.gridheight = height;
gbl.setConstraints(component, gbc);
panel.add(component);
}
private void addPanel1Components()
{
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
pSoft.setLayout(gbl);
addComponent(Panel1, lblName, 0, 0, 1, 2, gbl, gbc);
...
// It is followed by other 10+ similar calls for all of the components to be placed on this panel
}
The question is should I create one global (for the current frame that is) GridBagLayout variable and use it with "new GridBagLayout()" operator for all panels or use the current approach?
As having a procedure with 8 parameters is kind of not good looking code and probably not the optimal one either.
NOTE: this question is also posted (but yet unanswered) here: [http://www.java-forums.org/awt-swing/22750-gridbaglayout-multiple-jpanels-single-jframe.html#post90045]