Code Organization Standard : <p>I am required to manually hand code all GUI's for my school assignments. I am working with Java and using GridBagLayout. I read that it is not a good idea to reuse the same GridBagConstraint instance and instead for each component to have it's own GridBagConstraint instance. So if each component gets its own and I specify fill, position, and insets for each one that leads to a lot of lines of code just for the GUI.</p>

<p>This particular assignment I will have a main pane in BorderLayout and 2 other panes that will sit inside that. One will be another BorderLayout that is just a display area for output information, the other will be the labels, text fields and buttons for a user to select multiple files to be used for input. I have broken it down and placed all code for each pane in its own JComponent instance(not sure if that is the correct term). So code looks like:</p>

<pre><code>protected JComponent inputPaneComponent() {
    all code for the inputPane goes here
}
</code></pre>

<p>But like I described above using multiple GridBagConstraints and specifics for each component leads to a long group of code. Should I break it apart with empty lines between each component maybe put a comment line above each one stating which component I am working with? Or just a long stack of lines?</p>

<p>This is just a sample I haven't finished coding it all yet. Something like this:</p>

<pre><code>protected JComponent inputPaneComponent() {
    JPanel inputPane = new JPanel();
    inputPane.setLayout(new GridBagLayout());
    inputPane.setBorder(BorderFactory.createTitledBorder("Input Files:"));
    GridBagConstraints c0 = new GridBagConstraints();
    c0.fill = GridBagConstraints.HORIZONTAL;
    c0.gridx = 0;
    c0.gridy = 0;
    c0.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameLabel, c0);
    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.HORIZONTAL;
    c1.gridx = 1;
    c1.gridy = 0;
    c1.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameFileTextField, c1);
    GridBagConstraints c2 = new GridBagConstraints();
    c2.fill = GridBagConstraints.HORIZONTAL;
    c2.gridx = 2;
    c2.gridy = 0;
    c2.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameFileButton, c2);
    return inputPane;
}
</code></pre>

<p>or This:</p>

<pre><code>protected JComponent inputPaneComponent() {
    // Set title, layout, and exit condition.
    JPanel inputPane = new JPanel();
    inputPane.setLayout(new GridBagLayout());
    inputPane.setBorder(BorderFactory.createTitledBorder("Input Files:"));

    // Create and configure name label.
    JLabel nameLabel = new JLabel("Names File:");
    GridBagConstraints c0 = new GridBagConstraints();
    c0.fill = GridBagConstraints.HORIZONTAL;
    c0.gridx = 0;
    c0.gridy = 0;
    c0.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameLabel, c0);

    // Create and configure name file textfield.
    JTextField nameFileTextField = new JTextField(60);
    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.HORIZONTAL;
    c1.gridx = 1;
    c1.gridy = 0;
    c1.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameFileTextField, c1);

    // Create and configure name file button.
    JButton nameFileButton = new JButton("Browse");
    GridBagConstraints c2 = new GridBagConstraints();
    c2.fill = GridBagConstraints.HORIZONTAL;
    c2.gridx = 2;
    c2.gridy = 0;
    c2.insets = new Insets(10, 10, 0, 0);
    inputPane.add(nameFileButton, c2);
    return inputPane;
}
</code></pre>

<p>I prefer the latter, as to me it is easier to read, but it does add to the length and I'm not that experienced and would like to know what the standard might be.</p>

<p>Thanks for your help, and I hope I'm within the rules for this forum, this is my first post here.</p>

<p>Matt</p>
