I would like to add different JPanel
to my JFrame
when the user clicks on a JButton
.
The Panel must change according to the button clicked by the user. Here is a portion of my code :
addCours.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
panCours.setBounds(215, 2, 480, 400);
panCours.setBorder(BorderFactory.createTitledBorder("Saisir les données concernant le cours"));
ConstituerData.this.getContentPane().add(panCours);
ConstituerData.this.revalidate();
ConstituerData.this.repaint();
}
});
addLocal.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
panLocal.setBounds(215, 2, 480, 400);
panLocal.setBorder(BorderFactory.createTitledBorder("Saisir les données concernant le local"));
ConstituerData.this.getContentPane().add(panLocal);
ConstituerData.this.revalidate();
ConstituerData.this.repaint();
}
});
How can I fix this ?