Results 1 to 2 of 2
  1. #1
    eramas is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default [swing] JDialog.dispose() not working.

    So I have a dialog with a "Cancel" button.
    The cancel button simply calls this.dispose() on actionPerformed().

    Everything works fine until I set the dialog as modal.
    If I use this.setModal(true); the dialog is modal (which is what I need) however the cancel button doesn't close the dialog anymore.

    Any ideas?

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: [swing] JDialog.dispose() not working.

    Works fine for me.
    Here's my code:
    Java Code:
    import java.awt.event.*;
    
    import javax.swing.JButton;
    import javax.swing.JDialog;
    
    
    public class Test extends JDialog implements ActionListener{
    	
    	private static final long serialVersionUID = 1L;
    
    	public static void main(String[] s){
    		Test t = new Test();
    		t.init();
    		
    	}
    	
    	public void init(){
    		JButton b = new JButton("Cancel");
    		b.addActionListener(this);
    		add(b);
    		pack();
    		setModal(true);
    		setVisible(true);
    	}
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		this.dispose();
    	}
    
    }

Similar Threads

  1. Problem Working through Oracle's Swing/Netbeans Tutorial.
    By rjschilling in forum New To Java
    Replies: 3
    Last Post: 08-13-2012, 11:33 PM
  2. dispose() method not working
    By R&R in forum New To Java
    Replies: 19
    Last Post: 11-15-2010, 01:46 AM
  3. dispose(); not working
    By Geraldo in forum AWT / Swing
    Replies: 12
    Last Post: 06-04-2010, 03:40 PM
  4. Swing components not working
    By primalpop in forum AWT / Swing
    Replies: 30
    Last Post: 11-15-2009, 05:10 PM
  5. Replies: 8
    Last Post: 08-27-2008, 11:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •