JFrame not responding to dispose() function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

JFrame not responding to dispose() function

amitSinghamitSingh IndiaPosts: 1Member

I am trying to code a program which pops up a file chooser window or dialog box to select a file first, if the user clicks 'cancel' or closes the window then the parent JFrame would not show up.
Code:

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.UnsupportedLookAndFeelException;
public final class base extends javax.swing.JFrame {
@SuppressWarnings("LeakingThisInConstructor")
public base() {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
try {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(base.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(base.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(base.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(base.class.getName()).log(Level.SEVERE, null, ex);
}
break;
}
}
initComponents();
setResizable(false);
chooseFile(this);
}
@SuppressWarnings("unchecked")
private void initComponents() {

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Java Image Viewer 1.0");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );

    pack();
}                        
public void chooseFile(base Base)
{
    int ret=new JFileChooser().showOpenDialog(this);
    if(ret==JFileChooser.CANCEL_OPTION)
        Base.dispose();
}
public void abort(base Base)
{
    Base.dispose();
}                  

}

The problem is that the JFrame shows up even if I click cancel in the file chooser.
I am using Netbeans.
Apologies for my poor English.

Sign In or Register to comment.