My program begins by allowing the chooser to select a file using a FileChooser Dialog. The filter I have set only allows .sgo files. But it does not display .sgo files when I compile and run the program and open the FileChooser Dialog (which means it only shows directories). However, it does say that "SGO" files are the only files allowed and only accepts .sgo when I manually enter the names of valid .sgo files.
The .sgo file contains only one object(which contains an array of other objects).
What is wrong in my code that is not allowing the FileChooser Dialog to show any files, when I want it to show only .sgo files?
openingDialogJButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e3) {
if (fc == null) {
fc = new JFileChooser();
//Add a sgo file filter and disable the default
ExtensionFileFilter filter = new ExtensionFileFilter("SGO", ".sgo");
fc.addChoosableFileFilter(filter);
fc.setAcceptAllFileFilterUsed(false);
}
//Show it.
int returnVal = fc.showDialog(TryTabbedObjectOutputWithActionListeners.this,
"Open");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
FileInputStream fIS = new FileInputStream(fc.getSelectedFile());
ObjectInputStream oIS = new ObjectInputStream(fIS); //line 195
Guide = (ObjectGuide) oIS.readObject();
jLabel6.setText(Guide.getNameOfGuide());
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(newGuideNamePanel,
"The File was not found.",
"File error1",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
ex.printStackTrace();
} catch (IOException e) {
JOptionPane.showMessageDialog(newGuideNamePanel,
"Corrupt File Error.",
"File error2",
JOptionPane.ERROR_MESSAGE);
//System.exit(1);
e.printStackTrace();
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(newGuideNamePanel,
"Class Not Found Error.",
"File error2",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
e.printStackTrace();
}
//Reset the file chooser for the next time it's shown.
fc.setSelectedFile(null);
OpeningDialog.setVisible(false);
}
This post has been edited by Mavsstarter21: 25 May 2011 - 02:07 AM

New Topic/Question
Reply


MultiQuote




|