JavaVM Windows 7 64bit - JFileChooser () does not show dialog

I am trying to create a simple Java console application that requires users to select files from their local file system.

The console will prompt the user to select one of the available options, and then enable the entered input.

public Client() throws UnknownHostException, IOException { printuseroptions(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char userdecision = br.readLine().charAt(0); System.out.println(userdecision); switch(userdecision){ case '1': System.out.println("Which file would you like to open?"); openfile(br.readLine()); break; case '2': System.out.println("Which file would you like to close?"); closefile(br.readLine()); break; } private boolean openfile(String path){ System.out.println("openfile("+path+")"); return false; } private boolean closefile(String path){ System.out.println("closefile("+path+")"); new JFileChooser().showOpenDialog(null); return false; } 

No matter what I do, the JFileChooser popup does not open. The error is not displayed on the console, but the debug step shows the following error:

Blockquote Theme [Home] (Paused)
Class NotFoundException (Throwable). (String, Throwable): 217
Class NotFoundException (Exception). (String, Throwable) String: Not available String of class ClassNotFoundException. (String): not available
URLClassLoader $ 1.run (): not available
AccessController.doPrivileged (PrivilegedExceptionAction, AccessControlContext): not available [native method]
Launcher $ ExtClassLoader (URLClassLoader) .findClass (string): not available
Launcher $ ExtClassLoader.findClass (string): not available
Launcher $ ExtClassLoader (ClassLoader) .loadClass (String, boolean) string: not available Launcher $ AppClassLoader (ClassLoader) .loadClass (String, boolean) string: not available Launcher $ AppClassLoader.loadClass (string, logical string): not available
Launcher $ AppClassLoader (ClassLoader) .loadClass (String): not available
ResourceBundle $ RBClassLoader.loadClass (string): not available
CoreResourceBundleControl (ResourceBundle $ Control) .newBundle (String, Locale, String, ClassLoader, boolean): not available
ResourceBundle.loadBundle (CacheKey, List, Control, boolean): not available ResourceBundle.findBundle (CacheKey, List, List, int, Control, ResourceBundle): not available
ResourceBundle.getBundleImpl (String, Locale, ClassLoader, ResourceBundle $ Control): not available
ResourceBundle.getBundle (String, ResourceBundle $ Control): not available
Toolkit $ 3.run () string: not available AccessController.doPrivileged (PrivilegedAction): not available [native method]
Toolkit. (): Not available
Component. (): Not Available
Version Client.closefile (): 90 Client. (): 60
Client.main (String []): 36

The same code works fine on a 32-bit Linux machine, so I suspect the problem is with Windows.

The code below works on both Windows and Linux, so I suspect this is due to various ways, while console input is processed on Windows vs Linux (CR LF).

 import javax.swing.JFileChooser; public class Example { public static void main(String[] args) { new JFileChooser().showOpenDialog(null); } } 

thanks

+1
java windows-7 64bit jfilechooser
source share
1 answer

It looks like you're as new as me;). Let's see if I can help.

I made changes to my code to make it compile and run it on a computer running Windows Server 2003 x64, and did not see any problems - the file selection dialog opens.

I suggest two things you can do to eliminate other possibilities:

1) Make sure that the appearance of the system is installed. Set the default appearance of the system using this when starting the program: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

2) Make sure that you only create and open your JFileChooserDialog and all other Swing components inside the event dispatch stream (EDT). If you know that the current thread is the main thread or some other worker thread (and I assume it is because you accept console input), you need to call SwingUtilities.invokeLater(Runnable) to execute correctly.

Good luck with that.

+1
source share

All Articles