Improving JFileChooser under Ubuntu 12.04 (GTK)

I have a problem with JFileChooserin Ubuntu 12.04. I use this code to set the look:   javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());

And it looks like this. This is very inconvenient to use, and it looks very ugly:

http://www9.picfront.org/token/9sRH/2012/05/15/2062476.jpg

I would like it to look like this:

http://www4.picfront.org/token/1lpa/2012/05/15/2062477.jpg

Using the hint from this post , I tried using FileDialoginstead FileChooser. But it FileDialogthrows an exception when I run it in mode LOADand click the open button. The way to create a dialogue:

FileDialog fd = new FileDialog(frame, "Test", FileDialog.LOAD);
fd.setVisible(true);

An exception:

Exception in thread "Thread-0" java.lang.NullPointerException
at sun.awt.X11.GtkFileDialogPeer.setFileInternal(GtkFileDialogPeer.java:79)
at sun.awt.X11.GtkFileDialogPeer.run(Native Method)
at sun.awt.X11.GtkFileDialogPeer.showNativeDialog(GtkFileDialogPeer.java:172)
at sun.awt.X11.GtkFileDialogPeer.access$000(GtkFileDialogPeer.java:39)
at sun.awt.X11.GtkFileDialogPeer$1.run(GtkFileDialogPeer.java:114)

I am using Oracle JDK7 under Ubuntu Linux 12.04 with Gnome 3 (if that helps).

- , JFileChooser FileDialog?

+5
3

Java GUI, . "zenity", - Linux/Unix. , - Java ( Zenity Linux, ), Windows:

private File fileSelection(boolean savemode) {
        String os = System.getProperty("os.name");
        File input = null;
        String zenity = "zenity --file-selection --title=Open";
        String filestring;
        if ((os.indexOf("nix")!=-1 || os.indexOf("nux")!=-1)) {
            //Use native Linux file selection.
            try {
                if (savemode) {
                    zenity ="zenity --file-selection --title=Save --save";
                }
                Process p = Runtime.getRuntime().exec(zenity);  
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));  
                StringBuffer sb = new StringBuffer();  
                String line;
                /*while ((line = br.readLine()) != null) {  
                  sb.append(line).append("\n");  
                } */
                sb.append(br.readLine());
                filestring = sb.toString();  
                if (filestring.equals("null")) {
                    return null;
                }
                System.out.println(filestring);
                input = new File(filestring);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        } else {
            final JFileChooser fc = new JFileChooser();
            int returnVal;
            if (savemode) {
                returnVal = fc.showSaveDialog(fc);
            } else {
                returnVal = fc.showOpenDialog(fc);  
            }
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                input = fc.getSelectedFile();
            }
        }
        return input;
    }
+2

, java-forum.org thread, .

eRaaaa , bugs.sun.com, .

+1

A NullPointerException usually means that you are pointing to something that is not there. I believe that the link you are trying to specify will be lost at runtime.

0
source

All Articles