You forgot to add bb
to the jDesktpPane1
. To do that, you need to take a JDesktopPane
argument as a parameter in your jInternalFrame1
. Then use that JDesktopPane
to add the second one. I put together a simple test run.
Code from MainFrame
private void jMenuItem1ActionPerformed(ActionEvent evt) {
IFrameOne iFrame1 = new IFrameOne(jDesktopPane1);
jDesktopPane1.add(iFrame1);
iFrame1.setVisible(true);
}
Code from IFrmaeOne
JDesktopPane desktop;
public IFrameOne(JDesktopPane desktop) {
initComponents();
this.desktop = desktop;
}
...
private void jButton1ActionPerformed(ActionEvent evt) {
IFrameTwo iFrameTwo = new IFrameTwo();
desktop.add(iFrameTwo);
this.dispose();
iFrameTwo.setVisible(true);
}
IFrameTwo
is just an empty JInternalFrame
class. This works for me. Created with GUI Builder also
UPDATE
"sir actually I tried cardLayout.But I cant add the cards using navigator (add from palette).For me coding is difficult.So I used drag and drop.Can you tell Why its not possible to add the cards?Yesterday I added.But today cant"
If you want to use a CardLayout
for the JInternalFrame
here are the steps
You can create
JPanel forms
. So create two of them.In your
JInternalFrame
drag and drop aJPanel
and extend it to the size of the frame.You need to hand code the
CardLayout
yourself. But it in the constructorpublic MyInternalFrame() { initComponents(); CardLayout cardlayout = new CardLayout(); jPanel1.setLayout(cardLayout); }
Then add the two
JPanel
forms you created in step one.jPanel1.add(new PanelForm1(), "panel1"); jPanel1.add(new PanelForm2(), "panel2");
Then in your
actionPerformed
you can just switch between panelspublic void jButton1ActionPerformed(java.awt.events.ActionEvent e) { cardLayout.show(jPanel1, "panel2"); }
You could switch back and forth if you need to.