I have One JFrame
and two JPanels
. Jframe
contains JTabbedPane
, MenuBar
and one menuItem
. When I click on the menuitem
, a panel is added to the JTabbedPane
. The code is this -
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NewJPanel jp = new NewJPanel();
jTabbedPane1.add("Panel",jp);
}
It is working fine. This panel contains a button. I want that on clicking the button a new panel to be added in JTabbedPane
. For the actionPerformed
method of button I am having this code -
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
NewJFrame1 jf = new NewJFrame1();
jf.addPanel();
}
addPanel is a method I have defined in JFrame. The code of addPanel()
is
public void addPanel()
{
System.out.println("Method Called");
NewJPanel1 jp1 = new NewJPanel1();
jTabbedPane1.add("Panel1",jp1);
}
But when I am clicking on the button I am getting "Method Called". It means that the method is being called, but the panel is not added to the JTabbedPane. Please help.
I have also tried this in the code of actionPerformed
Method of button after making JTabbedPane1 public in JFrame-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
NewJFrame1 jf = new NewJFrame1();
NewJPanel1 pane = new NewJPanel1();
jf.jTabbedPane1.add("Panel1",pane);
}
But this is also not adding the Panel. What should I do?