I've got a bit of a problem with JFileChooser. I have a class extending SimpleGame with a JMEDesktop which has some buttons in a menu. When I click on a button, I would like a JFileChooser to appear, let me select a 3DS and then import in the scene.
private void newActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("New pressed");
//newProjectDialog = new JInternalFrame("New Project");
JInternalFrame tempFrame = new JInternalFrame("New Project");
//System.out.println("newProjectDialog components count : " + newProjectDialog.getContentPane().getComponentCount());
JFileChooser fileChooser = new JFileChooser();
fileChooser.addChoosableFileFilter(new ImageFilter());
fileChooser.setAcceptAllFileFilterUsed(false);
//Add custom icons for file types.
fileChooser.setFileView(new ImageFileView());
//Add the preview pane.
fileChooser.setAccessory(new ImagePreview(fileChooser));
tempFrame.add(fileChooser);
//Show it.
int returnVal = fileChooser.showDialog(null,
"New Project");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
System.out.println("Attaching file: " + file.getName());
} else {
System.out.println("Attachment cancelled by user.");
}
//Reset the file chooser for the next time it's shown.
fileChooser.setSelectedFile(null);
System.out.println("it should show");
//this.
}
The fileChooser does appear, but if I move it a bit around, it looks like this :
So far it crashes my application, if i press alt+tab.
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d15d2e8, pid=1908, tid=240
#
# Java VM: Java HotSpot(TM) Client VM (11.0-b09 mixed mode, sharing windows-x86)
# Problematic frame:
# C [awt.dll+0xad2e8]
#
# An error report file with more information is saved as:
# E:programareJavaMy projectsTest3hs_err_pid1908.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
I’ve declared a JInternalFrame and I put the fileChooser in it in a function which I call in the swing thread. It shows now properly, but now I need to figure out how to make it close or import my object in my scene.