Buonasera,
Sto usando come Layout GridBagLayout;
Vorrei mettere in riga, due (o più) Panel, composti da tre elementi.
Il problema è che a Video si vede solo il primo Panel, mentre il secondo non compare.
Vi posto il codice:
public class GUI {
private JFrame frame;
private JPanel panel;
private JPanel panel_A;
private JPanel panel_B;
private JPanel panel_C;
private GridBagLayout GBL;
private GridBagConstraints GBC;
public GUI() {
frame = new JFrame("Prova");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
panel = new JPanel();
GBL = new GridBagLayout();
panel.setLayout(GBL);
GBC = new GridBagConstraints();
GBC.anchor = GridBagConstraints.WEST;
GBC.gridx=0;
GBC.gridy=1;
panel_A = new JPanel();
panel_A.add(new JTextField("TEST A"));
panel_A.add(new JButton("A"));
panel_A.add(new JLabel("A"));
GBL.setConstraints(panel_A,GBC);
panel.add(panel_A);
panel_B = new JPanel();
panel_B.add(new JTextField("TEST B"));
panel_B.add(new JButton("B"));
panel_B.add(new JLabel("B"));
GBL.setConstraints(panel_B,GBC);
panel.add(panel_B);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
Dove sbaglio?
Grazie.