Solved

Problem closing a JInternalFrame

Posted on 1998-07-24
12
320 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 74
Facing this issue for maven proxy setting 2 44
Notify sent to other threads in Java 9 54
Java 8 to Java 6 8 41
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

739 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