JFileChooser ignoring special character folders on OS X
Asked Answered
B

2

8

I have one Java program that browse the path of our local file system, for this we have used JFileChooser. If folder name is in simple English works fine on Windows, Mac OS X and Linux. But If I create folder named special character like - ábc Eóz then it shows that special character name on Windows and Linux only, but on OS X I am unable to see those special character folders. It ignore them from list of folders.

My program is built on java 7 update 21. Mac OS X version - 10.8.2

How can I solve this issue?

Thanks

UPDATE : We are creating an app for Mac using JavaFX packaging. When we are running app.jar directly, it showing me path containing special char. But if we are trying to launch application using app then it skipped that special char folders.

Bile answered 12/7, 2013 at 10:17 Comment(4)
Related: #14073119 and #1546125Giza
Have you tried -Dfile.encoding=UTF-8 as mentioned in the above referenced posts?Caritta
@ShadowCreeper I hadn't noticed the comment in one of the questions mentioning -Dfile.encoding=UTF-8, I will try that when I get home. Where am I supposed to put that command? Is it a parameter when starting the JVM or something that should be put somewhere in my code?Reset
@AdamSmith Yes, it's a JVM parameter.Caritta
B
0

As we are building app using JavaFX packaging and we have our customized Info.plist kept inside ..buildscript_path/package/macosx/ folder at local path.

The problem of ignoring special characters get resolved by adding following keys to Info.plist.

 <key>LSEnvironment</key>
 <dict>
    <key>LANG</key>
    <string>en_US.UTF-8</string>
 </dict> 

On adding this line of code into info.plist, then building app solved my issue.

Thanks

Bile answered 3/2, 2014 at 6:59 Comment(1)
It seems like I hadn't noticed the JavaFX tag in the question when I posted the bounty and I hadn't thought it would actually make a difference. I'm not using JavaFX for my application, so this solution will not work for me. Thanks for the answer, though, it will probably come in useful for other people.Reset
N
2

I just tried a sample:

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;

public class Trial {
    public static void main(String... args) {
        JFrame frame = new JFrame("FrameDemo");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel emptyLabel = new JLabel();

        frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

        frame.pack();

        frame.setVisible(true);

        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(frame);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            System.out.println("You chose to open this file: " +
                    chooser.getSelectedFile().getName());
        }
    }
}

on a OS X 10.9.1 running JDK 1.7.0_51. I created the following folders hierarchy: ~/Documents/Joyeux Naufragés/ábc Eóz: enter image description here.

In order to address the problem you described I installed also the JDK you pointed out, JDK_1.7.0_25 and I managed to reproduce the same issue, here is the snapshot for the same window running u25 enter image description here

As one can see the folders containing special characters don't show. So I checked also with JDK 1.7.0_40 and surprise - it works. After that I went over the bugs fixed in the given version, I found out that several bugs related mac os x where fixed in this release. Among which a couple (7024118, 7032018, 7032436, 7161437) refer to issues in JFileChooser. There are other issues related to mac (45 in total) out of which one refers to FileDialog. Unfortunately the links to the bug descriptions don't work, so I cannot post more info on the subject, but the solution for your issue is definitely to update to at least version 1.7.0_40 even if I suppose the best would be to update to the latest (1.7.0_51).

Good luck with your work. I hope this helps you.

Nedanedda answered 9/2, 2014 at 8:40 Comment(2)
Hi, thanks for the answer. This is similar to what I had tried and the folders and files with special characters (like "é" in this case) still aren't displayed. I'm running jdk1.7.0_25 on OS X 10.9.1.Reset
@AdamSmith - thank you for your feedback, this is what I was waiting to be honest.Nedanedda
B
0

As we are building app using JavaFX packaging and we have our customized Info.plist kept inside ..buildscript_path/package/macosx/ folder at local path.

The problem of ignoring special characters get resolved by adding following keys to Info.plist.

 <key>LSEnvironment</key>
 <dict>
    <key>LANG</key>
    <string>en_US.UTF-8</string>
 </dict> 

On adding this line of code into info.plist, then building app solved my issue.

Thanks

Bile answered 3/2, 2014 at 6:59 Comment(1)
It seems like I hadn't noticed the JavaFX tag in the question when I posted the bounty and I hadn't thought it would actually make a difference. I'm not using JavaFX for my application, so this solution will not work for me. Thanks for the answer, though, it will probably come in useful for other people.Reset

© 2022 - 2024 — McMap. All rights reserved.