Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFileChooser ignoring special character folders on OS X

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.

like image 588
Neelam Sharma Avatar asked Jul 12 '13 10:07

Neelam Sharma


1 Answers

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.

like image 152
Olimpiu POP Avatar answered Oct 15 '22 09:10

Olimpiu POP