views:

156

answers:

3
A: 

From your description, option 1 should work. Give the Input JPanel a BorderLayout, with the Details, Crime and Button JPanels (at the west, north and south, respectively) having GridLayouts.

Matthew Murdoch
+5  A: 

Okay, your description is a little bit confusing (or I'm still too tired today or didn't have enough caffeine yet). Your notion of "calling" panel classes from others is also a little weird.

But as far as I can see it, your first option is the correct one.

In general you just nest the objects at runtime, so it might look a little like the following:

InputPanel (has BorderLayout)
+--DetailsPanel (put in BorderLayout.WEST; has GridLayout)
|  +--nameLabel
|  +--nameTextField
|  +--...
+--CrimePanel (put in BorderLayout.NORTH; has GridLayout)
|  +--murderRadioButton
|  +--arsonRadioButton
|  +--...
+--ButtonPanel (put in BorderLayout.CENTER; has GridLayout)
   +--button

You usually do this in the constructor of the appropriate class:

public class InputPanel {
    public InputPanel() {
        this.setLayout(new BorderLayout());
        this.add(new DetailsPanel(), BorderLayout.WEST);
        this.add(new CrimePanel(), BorderLayout.NORTH);
        this.add(new ButtonPanel(), BorderLayout.CENTER);
    }
}

public class DetailsPanel {

    JLabel nameLabel;
    JTextField nameField;
    // ...

    public DetailsPanel() {
        this.setLayout(new GridLayout(5, 1));

        nameLabel = new JLabel("Name");
        nameField = new JTextField();
        // ...

        this.add(nameLabel);
        this.add(nameField);
        // ...
    }
}

...

However, I see a small problem here: Since GridLayout doesn't allow components to span multiple columns you may need to nest other panels in the DetailsPanel on the left as well. You can get away with a single GridBagLayout which has the needed capabilities, or you nest other panels there:

DetailsPanel (has BorderLayout)
+--panel1 (has GridLayout with 2 rows, 1 column; put in BorderLayout.NORTH)
|  +--nameLabel
|  +--nameField
+--panel2 (has GridLayout with 3 rows, 2 columns; put in BorderLayout.CENTER)
   +--dayField
   +--dayLabel
   +--monthField
   +--...
Joey
The centred name label and text field vs side-by-side elements in the rest of West will need some subordinate layout, though. Either GridBag the whole of West or give it a BorderLayout, with the name bits in one panel in North and the rest in another in Center, with a Grid layout on each sub-panel.
Steve Gilham
Already edited :) Noticed that when trying to create the class stubs.
Joey
A: 

First of all you will need to put a JTabbedPane into the Window to contain your two tabs (input and display), each consisting of a JPanel.

The input panel could be subdivided using a BorderLayout as Joannes describes; another alternative is the GroupLayout introduced in Java 6, which is very powerful, but hard to wrap your mind around. It could be used to layout the entire tab in one panel.

Michael Borgwardt