GridBagLayout and multiple JPanel's on a single JFrame
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 GridBagLayout as it will contain labels, text fields and text areas.
Here is the current code I use to set up layouts on all panels
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?
// 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;
private void addPanel1Components()
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
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
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 here: