Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem closing a JInternalFrame

Posted on 1998-07-24
12
Medium Priority
?
329 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

610 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