Solved

Problem closing a JInternalFrame

Posted on 1998-07-24
12
325 Views
Last Modified: 2010-03-30
I created a JInternalFrame and called setClosable(true).  The problem is that the frame does not close.  Any suggestions?
0
Comment
Question by:mwalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 

Expert Comment

by:Gamestor
ID: 1228138
Hi mwalker,

How about using setClosed(true) or dispose().

Good luck
0
 

Author Comment

by:mwalker
ID: 1228139
Are you saying that I have to add a window listener to the Internal Frame?  In the SwingSet applet example, I did not see in that in the code.  All that was done was a call to setClosable(true) on the frame.
0
 
LVL 4

Expert Comment

by:evijay
ID: 1228140
please give sample code
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:mwalker
ID: 1228141
Here is my code:

import java.awt.Container;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

import com.sun.java.swing.JComponent;
import com.sun.java.swing.JInternalFrame;
import com.sun.java.swing.JPopupMenu;
import com.sun.java.swing.JPanel;
import com.sun.java.swing.JMenuItem;
import com.sun.java.swing.JSeparator;
import com.sun.java.swing.JButton;
import com.sun.java.swing.event.InternalFrameListener;
import com.sun.java.swing.event.InternalFrameEvent;

class CAARptViewer extends JInternalFrame implements InternalFrameListener
{
    private Container contentPane;
    protected JPanel thePanel;
    private JPopupMenu popupMenu;

    public CAARptViewer(String title)
    {
        super(title, false, true, true, true);

        contentPane = getContentPane();
        contentPane.setLayout(new GridLayout());

        // create and add the pane that holds the report
        thePanel = new JPanel();
        thePanel.setLayout(new GridLayout());
        contentPane.add(thePanel);

        setBounds(0, 0, 545, 175);
        try {
            setSelected(true);
        }
        catch (java.beans.PropertyVetoException e) {}

        addInternalFrameListener(this);
    }

    //{ Listeners
    public void internalFrameActivated(InternalFrameEvent e)
    {
        System.out.println("Window is activated");
    }
    public void internalFrameClosed(InternalFrameEvent e)
    {
        System.out.println("Closing internal window!");
        dispose();
    }
    public void internalFrameClosing(InternalFrameEvent e) { }
    public void internalFrameDeactivated(InternalFrameEvent e) { }
    public void internalFrameDeiconified(InternalFrameEvent e) { }
    public void internalFrameIconified(InternalFrameEvent e) { }
    public void internalFrameOpened(InternalFrameEvent e) { }
    //}
}
0
 
LVL 4

Expert Comment

by:evijay
ID: 1228142
void setDefaultCloseOperation(int)
         int getDefaultCloseOperation()


Set or get the operation that occurs when the user pushes the close button on this internal frame. Possible choices
                                      are:

                                          DO_NOTHING_ON_CLOSE
                                          HIDE_ON_CLOSE (the default)
                                          DISPOSE_ON_CLOSE

                                      These constants are defined in the WindowConstants interface.
0
 
LVL 4

Expert Comment

by:evijay
ID: 1228143
public void internalFrameClosed(InternalFrameEvent e)
          {
              System.out.println("Closing internal window!");
              dispose();
          }


replace with

public void internalFrameClosed(InternalFrameEvent e)
          {
              System.out.println("Closing internal window!");
              setVisible(false);
              dispose();
          }

0
 

Author Comment

by:mwalker
ID: 1228144
Sorry, this didn't work for me either.  I should add that CAARptViewer is being added to an object subclassed from JDeskTop.  Any ideas would be greatly appreciated.
0
 
LVL 4

Expert Comment

by:evijay
ID: 1228145
replace -->

public CAARptViewer(String title)
           {
               super(title, false, true, true, true);

               contentPane = getContentPane();
               contentPane.setLayout(new GridLayout());

               // create and add the pane that holds the report
               thePanel = new JPanel();
               thePanel.setLayout(new GridLayout());
               contentPane.add(thePanel);

               setBounds(0, 0, 545, 175);
               try {
                   setSelected(true);
               }
               catch (java.beans.PropertyVetoException e) {}

               addInternalFrameListener(this);
           }

with


public CAARptViewer(String title)
           {
               super(title, false, true, true, true);
               setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE );
               contentPane = getContentPane();
               contentPane.setLayout(new GridLayout());

               // create and add the pane that holds the report
               thePanel = new JPanel();
               thePanel.setLayout(new GridLayout());
               contentPane.add(thePanel);

               setBounds(0, 0, 545, 175);
               try {
                   setSelected(true);
               }
               catch (java.beans.PropertyVetoException e) {}

           }
0
 
LVL 4

Expert Comment

by:evijay
ID: 1228146
sorry reject the answer - typo
0
 

Author Comment

by:mwalker
ID: 1228147
I hate to be the bearer of bad news, but I added the call to setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE ) and it still did not work.
0
 

Author Comment

by:mwalker
ID: 1228148
I have solved this problem.  Thank you anyway.
0
 
LVL 3

Accepted Solution

by:
sailwind earned 100 total points
ID: 1228149
In your internal frame, add this:

addWindowListener(new WindowCloser());

and make an inner class:

class WindowCloser extends WindowAdapter
{
  public void windowClosing(WindowEvent e)
  {
    Window win = e.getWindow();
    win.setVisible(false);
    win.dispose();
  }
}

 
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question