[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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");
      }

   }
}
0
ganown
Asked:
ganown
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now