JInternalFrame Not Closing in JDesktopPane

Hello All,

The JInternalFrame which opens inside a JDeskTopPane closes for the first time when I click on the top right and when I opens the JInternalFrame again without going out of the Application it is not closing it. I have tried in many ways, but I don't understand what is the mistake I am making. I am using jdk1.2.1. Below I have attached the code. It will be great, if any one can help me out to find a solution for this problem.

Thanks In Advance,
Ganesh


import java.awt.BorderLayout;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class windowVerify extends JFrame
{
   JDesktopPane deskTop;
   JInternalFrame displayFrame;
   public windowVerify()
   {
      try
      {
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e)
      {
         System.out.println("Exception-1 " + getClass().getName() + " - Default Constructor : " + e.getMessage() + " : " + e.toString());
      }

      try
      {
         deskTop = new JDesktopPane();
         intlFrame iFrame = new intlFrame();
         this.setJMenuBar(iFrame.getMenus ());
         displayFrame = iFrame.getFrame();
     
         deskTop.setOpaque (false);

         getContentPane().add(deskTop, BorderLayout.CENTER);

      }
      catch(Exception e)
      {
         System.out.println("Exception-2 " + e.getMessage () + e.toString ());
      }

   }
   
   public static void main(String[] args)
   {
      windowVerify frame = new windowVerify();
      frame.setSize(200,200);
      frame.show ();
   }

   

   public class intlFrame extends InternalFrameAdapter
   {
      JInternalFrame jFrame;
      public intlFrame()
      {
         jFrame = new JInternalFrame("Window Verify",true,true,true,true);
         jFrame.setSize(150,150);
         JPanel panel = new JPanel();
         panel.setSize(100,100);
         panel.setVisible(true);
         jFrame.getContentPane ().add(panel);
      }

      public JInternalFrame getFrame()
      {
/*         jFrame.addInternalFrameListener (new InternalFrameListener(){
                 public void internalFrameActivated(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameActivated");
                 }
                 public void internalFrameClosed(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameClosed");
                 }
                 public void internalFrameIconified(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameIconified");
                 }
                 public void internalFrameClosing(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameClosing");
                 }
                 public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameDeactivated");
                 }
                 public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameDeiconified");
                 }
                 public void internalFrameOpened(javax.swing.event.InternalFrameEvent A)
                 {
                    System.out.println("internalFrameOpened");
                 }
                 });*/
         return jFrame;
      }

      public JMenuBar getMenus()
      {
         JMenuBar menuBar = new JMenuBar();
         JMenu menu = new JMenu("File");
         JMenuItem menuItem1 = new JMenuItem("Show");
         menuItem1.addActionListener (new ActionListener(){
                 public void actionPerformed(java.awt.event.ActionEvent A)
                 {
                    deskTop.add(getFrame(), JDesktopPane.PALETTE_LAYER);
                 }
         });
         JMenuItem menuItem2 = new JMenuItem("Remove");
         menuItem2.addActionListener (new ActionListener(){
                 public void actionPerformed(java.awt.event.ActionEvent A)
                 {
                    deskTop.remove(jFrame);

                 }
         });
         JMenuItem menuItem3 = new JMenuItem("Exit");
         menuItem3.addActionListener (new ActionListener(){
                 public void actionPerformed(java.awt.event.ActionEvent A)
                 {
                    System.exit(0);
                 }
         });

         menu.add(menuItem1);
         menu.add(menuItem2);
         menu.add(menuItem3);
         menuBar.add(menu);

         return menuBar;
      }

      public void internalFrameActivated(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameActivated");
      }
      public void internalFrameClosed(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameClosed");
      }
      public void internalFrameIconified(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameIconified");
      }
      public void internalFrameClosing(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameClosing");
      }
      public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameDeactivated");
      }
      public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameDeiconified");
      }
      public void internalFrameOpened(javax.swing.event.InternalFrameEvent A)
      {
         System.out.println("internalFrameOpened");
      }

   }
}
ganownAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mwibbelsCommented:
This is a slight bug in my view. I changed one actionlistener to the following:

menuItem1.addActionListener (new ActionListener(){
           public void actionPerformed(java.awt.event.ActionEvent A) {
                try {
                     getFrame().setClosed(false);
                }
                catch (Exception e) {
                      // might throw property veto exception
                }
               deskTop.add(getFrame(), DesktopPane.PALETTE_LAYER);
     }
});

This works for me. I'm using JDK 1.2.2 by the way, but initially I had the same behavior as you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ganownAuthor Commented:
mwibbels,

It is working fine, but why it is working for the first time alone and why not on the second time.

Ganesh
0
ganownAuthor Commented:
Sorry, for not clearly mentioning the problem.  After I added your code it is working fine.  But, without including your code, why it is working for the first time alone?

Ganesh
0
mwibbelsCommented:
Because 'isClosed' is a state that is cleared at JInternalFrame creation time. Then you close it, so it is set. But when you re-add it again the 'isClosed' state is not reset.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.