Solved

Problem closing a JInternalFrame

Posted on 1998-07-24
12
281 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array11 challenge 16 52
stringclean challenge 26 57
wordmultiple challenge 12 92
Eclipse IDE - Cannot copy/paste from console output 8 70
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now