I need to know how I can JMenuItem
open JPanel
, that is, by clicking JMenuItem
, open the corresponding JPanel, this in Eclipse, through windowBuilder.
This is the image of my screen with the menu:
Image of the screen with the menu 1
JPanel call code:
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Agenda1 window = new Agenda1();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Agenda1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new CardLayout(0, 0));
-- -- -
JPanel panelEditar = new JPanel();
frame.getContentPane().add(panelEditar, "name_5905325036674");
panelEditar.setLayout(new CardLayout(0, 0));
-- -- --
JMenuItem mntmEditar = new JMenuItem("Editar");
mntmEditar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
CardLayout card = (CardLayout) frame.getContentPane().getLayout();
card.show(frame.getContentPane(), "panelEditar");
}
});
The full code here: link