[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?
Re: [swing] JDialog.dispose() not working.
Works fine for me.
Here's my code:
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();
}
}