开发者

JFileChooser returns not all path

开发者 https://www.devze.com 2023-01-30 16:30 出处:网络
using following method on Path button click: public static void pathButtonAction() { JFileChooser chooser = new JFileChooser();

using following method on Path button click:

public static void pathButtonAction() {
    JFileChooser chooser = new JFileChooser();
    if (pathToInbound == null) { //private static File pathToInbound;
    chooser.setCurrentDirectory(new java.io.File("."));
    } else {chooser.setCurrentDirectory(pathToInbound);
            }

    chooser.setDialogTitle("Choose folder with messages to send");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        pathToInbound = chooser.getCurrentDirectory(); 
        addLogText(chooser.getCurrentDirectory().getAbsolutePath());
 开发者_运维问答   }


}

But here i choose folder c:\windows\temp Here addLogText(chooser.getCurrentDirectory().getAbsolutePath()) i get to log only c:\windows. Why temp folder was ignored/truncated?


You should call chooser.getSelectedFile() instead of chooser.getCurrentDirectory(), this returns the current directory where the user has navigated in the filechooser. In your case it is C:\Windows.

0

精彩评论

暂无评论...
验证码 换一张
取 消