Reputation: 1080
Is there any way that I could add panels in bottom-to-top order?..
I've tried some layout managers, but still i couldn't get it.. need help.
JPanel mainpanel = new JPanel();
JPanel panel_1 = new JPanel();
JPanel panel_2 = new JPanel();
JPanel panel_3 = new JPanel();mainpanel.add(panel_1);
mainpanel.add(panel_2);
mainpanel.add(panel_3);
mainpanel.add(panel_4);
mainpanel.add(panel_5);
mainpanel.add(panel_n);
Upvotes: 2
Views: 3789
Reputation: 1200
MigLayout works here as well - and increases maintainabilty:
JPanel mainpanel = new JPanel(new MigLayout();
private void addPanel(JPanel newPanel) {
mainpanel.add(newPanel, "dock north");
}
Upvotes: 1
Reputation: 168
Add the panel in order, In which order you want to display in the frame. Let p1,p2,p3 are the subv-panels and p is main panel. You want order of panel as folowing : p2,p3,p1 p.add(p2); p.add(p3); p.add(p1); then finally add it to your frame. I think this will help you.
Upvotes: 0
Reputation: 1247
You should be able to specify an index for adding the panel. Ie:
mainpanel.add(panel_1, 0);
mainpanel.add(panel_2, 0);
mainpanel.add(panel_3, 0);
This will always add each panel in the first position.
Upvotes: 2