2 Replies - 1023 Views - Last Post: 02 February 2013 - 02:55 PM Rate Topic: -----

#1 sh_emami65   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-February 13

JFrame not exiting properly when set on DISPOSE_ON_CLOSE?

Posted 02 February 2013 - 11:25 AM

Hi

I have been using the code block below as my standard GUI start. However, for some reason after I updated eclipse and JDK to their newest versions, it just doesn't work anymore and I have no idea why.

exit() gets called and frame properly dispersers but it seems there is a daemon thread and a AWT thread active, according to eclipse debug. This should not be happening.

I don't want to use System.exit(0) or EXIT_ON_CLOSE. I'm not looking for another way to solve this, I want to know why this is not working. have covered all my steps, and the program is written properly.

I am running this program as is right now there are no other thread sunning with it.

Any help or advise will be appreciated, thanks.

import java.awt.Toolkit;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class JFrameTest extends JFrame implements Runnable{
	
	private final Listener manager;
	
	private JButton jbExit;
	
	public JFrameTest(){
		super("JFrame Test");
		try {
			UIManager.setLookAndFeel( UIManager. getSystemLookAndFeelClassName());
		} catch ( Exception e) {
			e.printStackTrace();
		}
		setResizable(false);
		manager = new Listener();
		addWindowListener( manager);
		setContentPane( createGUI());
		setDefaultCloseOperation( DISPOSE_ON_CLOSE);
		pack();
		setMinimumSize( new Dimension( 250,150));
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation( (screenSize.width/2)-(getWidth()), (screenSize.height/2)-(getHeight()));
	}
	
	private Container createGUI() {
		JPanel jpMain = new JPanel();
		jpMain.setLayout( new FlowLayout( FlowLayout.CENTER));
		
		jbExit = new JButton( "Exit");
		jbExit.addActionListener( manager);
		
		jpMain.add( jbExit);
		
		return jpMain;
	}

	@Override
	public void run() {
		setVisible( true);
	}
	
	protected class Listener extends WindowAdapter implements ActionListener{
		@Override
		public void windowClosing(WindowEvent e) {
			exit();
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			exit();
		}
		
		private boolean exit(){
			dispose();
			//anyother cleaning
			return true;
		}
	}
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater( new JFrameTest());
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: JFrame not exiting properly when set on DISPOSE_ON_CLOSE?

#2 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: JFrame not exiting properly when set on DISPOSE_ON_CLOSE?

Posted 02 February 2013 - 02:07 PM

It's exiting properly for me. Nothing extra running. Verified with the netbeans debugger.
Was This Post Helpful? 0
  • +
  • -

#3 sh_emami65   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-February 13

Re: JFrame not exiting properly when set on DISPOSE_ON_CLOSE?

Posted 02 February 2013 - 02:55 PM

View Postfarrell2k, on 02 February 2013 - 04:07 PM, said:

It's exiting properly for me. Nothing extra running. Verified with the netbeans debugger.

thanks for ur reply, i am gonna check it with my other computer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1