Which Layout manager should I use to be able to position the panels as in the illustrative image below.
Edit: I have the PanelX Class, which I set in JFrame
as position SOUTH
, inside this class I have 2 panels (Panel 02 and 03), I want to orient one panel to the left and the other one to the right.
I tried to apply BorderLayout
to position secondary panels (panels 2 and 3), but it did not work.
ExampleofwhatIdid:
packagetool;importjava.awt.BorderLayout;importjava.awt.Color;importjavax.swing.JComponent;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;publicclassTesteextendsJFrame{publicstaticvoidmain(String[]args){Testeteste=newTeste();teste.setVisible(true);}privatePainelXpainel=newPainelX();publicTeste(){setSize(600,400);getContentPane().add("South", painel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
class PainelX extends JPanel
{
public PainelX()
{
setBackground(Color.red);
add(painel02(), BorderLayout.EAST);
add(painel03(), BorderLayout.WEST);
}
private JComponent painel02()
{
JPanel painel = new JPanel();
JLabel teste = new JLabel("Painel 02");
painel.add(teste);
return painel;
}
private JComponent painel03()
{
JPanel painel = new JPanel();
JLabel teste = new JLabel("Painel 03");
painel.add(teste);
return painel;
}
}