Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5265

JFrame.DISPOSE_ON_CLOSE

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.gui
Subject JFrame.DISPOSE_ON_CLOSE
Date 2012-11-02 15:34 -0700
Organization A noiseless patient Spider
Message-ID <k71hp3$is5$1@dont-email.me> (permalink)

Show all headers | View raw


Hey guys:

I was working on a small project and put my usual closing code in on the 
JFrame menu and the program doesn't end.  I think I remember it doing 
that before but maybe I'm losing my mind again.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JPanel {
     public test() {
         setPreferredSize(new Dimension(400,300));
     }

     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 final JFrame f = new JFrame("test");
                 f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                 JMenuBar mb = new JMenuBar();
                 f.setJMenuBar(mb);
                 JMenu file = new JMenu("File");
                 mb.add(file);
                 JMenuItem quit = new JMenuItem("Quit");
                 quit.addActionListener(new ActionListener() {
                     public void actionPerformed(ActionEvent ae) {
                         f.setVisible(false);
                     }
                 });
                 file.add(quit);

                 f.add(new test(),BorderLayout.CENTER);
                 f.pack();
                 f.setVisible(true);
             }
         });
     }
}

Close the window with the X in the upper corner and the program exits. 
Use the File Quit menu and it never exits.  I thought setting 
DISPOSE_ON_CLOSE would cause it to end or have I completely forgotten 
something.

Running on Windows XP with Oracle 7u9.

Thanks,

knute...

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

JFrame.DISPOSE_ON_CLOSE Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-11-02 15:34 -0700
  Re: JFrame.DISPOSE_ON_CLOSE Joerg Meier <joergmmeier@arcor.de> - 2012-11-02 23:40 +0100
  Re: JFrame.DISPOSE_ON_CLOSE markspace <-@.> - 2012-11-02 15:40 -0700
  Re: JFrame.DISPOSE_ON_CLOSE Roedy Green <see_website@mindprod.com.invalid> - 2012-11-06 21:27 -0800

csiph-web