Solved

Problem closing a JInternalFrame

Posted on 1998-07-24
12
300 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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.

831 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