JavaVM的Windows 7的64位 - JFileChooser中()不显示对话框 [英] JavaVM Windows 7 64bit - JFileChooser() not showing dialog box

查看:385
本文介绍了JavaVM的Windows 7的64位 - JFileChooser中()不显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的基于控制台的Java应用程序,这就要求用户从他们的本地文件系统中选择文件。

I am trying to create a simple console based java application, which requires users to select files from their local filesystem.

控制台提示用户选择可用选项之一,然后接通给定了输入

The console prompts the user to select one of the available options and then switches on the input given.

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;
}

无论我做什么,JFileChooser中弹出对话框无法打开。没有错误显示在控制台上,但调试步骤,通过显示了以下错误:

No matter what I do, the JFileChooser pop up box will not open. No error is shown on the console, but a debug step-through shows the following error:

块引用   螺纹[主](暂停)
      。ClassNotFoundException的(可抛出)(字符串,可抛出)线:217
      。ClassNotFoundException的(异常)(字符串,可抛出)线:不可用       。ClassNotFoundException的(字符串)行:不可用
      URLClassLoader的$ 1.运行()线:不可用
      AccessController.doPrivileged(的PrivilegedExceptionAction,AccessControlContext的)行:不可用[本地方法]
      启动$的ExtClassLoader(的URLClassLoader).findClass(字符串)行:不可用
      启动$ ExtClassLoader.findClass(字符串)行:不可用
      启动$的ExtClassLoader器(classloader).loadClass(字符串,布尔)线:不可用       启动$ AppClassLoader器(classloader).loadClass(字符串,布尔)线:不可用       启动$ AppClassLoader.loadClass(字符串,布尔)线:不可用
      启动$ AppClassLoader器(classloader).loadClass(字符串)行:不可用
      资源包$ RBClassLoader.loadClass(字符串)行:不可用
      CoreResourceBundleControl(资源包$控制).newBundle(字符串,区域设置,字符串,类加载器,布尔)线:不可用
      ResourceBundle.loadBundle(CacheKey,列表,控制,布尔)线:不可用       ResourceBundle.findBundle(CacheKey,列表,列表,INT,控制,资源包)线:不可用
      ResourceBundle.getBundleImpl(字符串,语言环境,类加载器,资源包$控制)线:不可用
      ResourceBundle.getBundle(字符串,资源包$控制)线:不可用
      工具包$ 3.run()行:不可用       AccessController.doPrivileged(将PrivilegedAction)行:不可用[本地方法]
      工具包()行:不可用
      组件()行:不可用
      Client.closefile()线:90       。客户端()线:60
      Client.main(字符串[])线路:36

Blockquote Thread [main] (Suspended)
ClassNotFoundException(Throwable).(String, Throwable) line: 217
ClassNotFoundException(Exception).(String, Throwable) line: not available ClassNotFoundException.(String) line: not available
URLClassLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction, AccessControlContext) line: not available [native method]
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available
Launcher$ExtClassLoader.findClass(String) line: not available
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available
ResourceBundle$RBClassLoader.loadClass(String) line: not available
CoreResourceBundleControl(ResourceBundle$Control).newBundle(String, Locale, String, ClassLoader, boolean) line: not available
ResourceBundle.loadBundle(CacheKey, List, Control, boolean) line: not available ResourceBundle.findBundle(CacheKey, List, List, int, Control, ResourceBundle) line: not available
ResourceBundle.getBundleImpl(String, Locale, ClassLoader, ResourceBundle$Control) line: not available
ResourceBundle.getBundle(String, ResourceBundle$Control) line: not available
Toolkit$3.run() line: not available AccessController.doPrivileged(PrivilegedAction) line: not available [native method]
Toolkit.() line: not available
Component.() line: not available
Client.closefile() line: 90 Client.() line: 60
Client.main(String[]) line: 36

同样的code完美运行在Linux 32位计算机上,所以我怀疑这个问题的Windows相关的。

The same code runs perfectly on a Linux 32 bit machine, so I suspect the problem is Windows related.

以下运行code按预期在Windows和Linux的,所以我怀疑可能是由于同时控制台输入在Windows处理VS Linux操作系统(CR LF)。

The code below runs as expected on both Windows and Linux so I suspect might be due to the different ways in while console input is handled in Windows vs Linux (CR LF).

import javax.swing.JFileChooser;

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

感谢

推荐答案

它看起来像你一样新来的,因为我。 ;)。让我们看看我能不能帮

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

我更改了code获得它来编译和运行它在Windows Server 2003 x64的计算机上,并没有发现任何问题 - 文件选择对话框打开

I made changes to your code to get it to compile, and ran it on a Windows Server 2003 x64 machine, and didn't see any problems - the file chooser dialog opens.

我建议两件事情可以做,以排除其他可能性:

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

1),保证了系统的本机外观和放大器;感觉被设置。设置你的外观和放大器;通过使用该感觉系统默认程序启动时: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

1) Ensure the system's native look & feel is set. Set your look & feel to the system default by using this when your program starts: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

2)确保你只构建并打开 JFileChooserDialog ,和所有其他的Swing组件,在事件指派线程(EDT)内。如果您知道当前线程是主线程或其他工作线程(我认为那是因为你正在做控制台输入),你需要调用 SwingUtilities.invokeLater(可运行)为正确执行。

2) Ensure you only construct and open your JFileChooserDialog, and all other Swing components, inside the Event Dispatch Thread (EDT). If you know the current thread is the main thread or some other worker thread (and I assume it is because you're taking console input), you need to call SwingUtilities.invokeLater(Runnable) for correct execution.

祝你好运。

这篇关于JavaVM的Windows 7的64位 - JFileChooser中()不显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆