Im designing a parent Jpanel contains JToolBar && inner JPanel.By the JToolBar's action i need to replace the inner JPanel with new JPanel which where i designed already. switching between different JPanels when pressing jtoolbar buttons. How can I do that in NetBeans IDE?
final CardLayout c = new CardLayout();
jPanel2 = new JPanel(c);
jPanel2.add(new BarChartPanel(), "CHART");
jPanel2.add(new ReportViewPanel(), "REPORT");
ClassLoader cldr = this.getClass().getClassLoader();
java.net.URL imageURL = cldr.getResource("Images/barimages.jpg");
ImageIcon aceOfDiamonds = new ImageIcon(imageURL);
JButton btnChart = new JButton(aceOfDiamonds);
btnChart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
c.show(jPanel2, "CHART");
}
});
jToolBar1.add(btnChart);
jToolBar1.addSeparator();
jToolBar1.setFloatable(false);
Here 'jPanel2' is my inner panel but while clicking the toolbars's button it's not diplaying!
Use a
CardLayout
for the layout of the "main panel's inner panel", as shown here.