Reputation: 49401
My code follows. I want 2 labels in a grid with the labels on top of each other and 2 dropdowns that have the same thing. I want two sets of these. What I get is just the two labels NEXT to each other and 2 dropdowns NEXT to each other and the first two labels and dropdowns dont appear at all the Dropdowns are the ones that are capitalized. No errors.
JPanel grid1 = new JPanel();
setLayout(new GridLayout(2,1));
grid1.add(label1);
grid1.add(label2);
add(grid1);
JPanel grid3 = new JPanel();
setLayout(new GridLayout(2,1));
grid3.add(IHA);
grid3.add(IVA);
add(grid3);
JPanel controlholder1 = new JPanel();
setLayout(new BorderLayout());
controlholder1.add(grid1);
controlholder1.add(grid3);
add(controlholder1);
JPanel grid2 = new JPanel();
setLayout(new GridLayout(2,1));
grid2.add(label3);
grid2.add(label4);
add(grid2);
JPanel grid4 = new JPanel();
setLayout(new GridLayout(2,1));
grid4.add(THA);
grid4.add(TVA);
add(grid4);
JPanel controlholder2 = new JPanel();
setLayout(new BorderLayout());
controlholder2.add(grid2);
controlholder2.add(grid4);
add(controlholder2);
Thanks
EDIT: I have 2 labels in a grid layout and I have 2 Dropdowns in another grid . I want both of these in a border layout and I need 2 of these border layouts in another border layout. There are nested things that I dont have a handle on.
Upvotes: 0
Views: 104
Reputation: 124
I would do this ;
public JPanel getSubPanels(stuff_to_add_to_dropdowns, stuff_to_add_to_labels){
JPanel subPanel = new JPanel();
subPanel.setLayout(new GridLayout(2,2));
subPanel.add(new JLabel(stuff_to_add_to_labels.get(0));
subPanel.add(new JComboBox(stuff_to_add_to_dropdowns.get(0);
subPanel.add(new JLabel(stuff_to_add_to_labels.get(1));
subPanel.add(new JComboBox(stuff_to_add_to_dropdowns.get(1);
return subPanel;
}
and call it twice adding it to BorderLayout.NORTH and BorderLayout.SOUTH to the parent JPanel
Upvotes: 1
Reputation: 1180
Add one label and one list in BorderLayout.NORTH and the other two in BorderLayout.SOUTH using BorderLayout
Upvotes: 1