Is there a way to improve JFileChooser look and feel under Ubuntu?
Asked Answered
S

4

6

I've been making a program that uses a JFileChooser. I've set the application up with

UIManager.getSystemLookAndFeelClassName()

Which works just fine for pretty much everything under Ubuntu. The only problem I've run into so far is that the JFileChooser comes out looking pretty awful: JFileChooser with SystemLookAndFeel

Is there a way to make this look like the default file chooser in Ubuntu? ie. Desired file chooser dialog

I've tried using

UIManager.getCrossPlatformLookAndFeelClassName()

Which makes the JFileChooser dialog look better, but still not native looking, and it ruins the rest off the application's feel too.

Thanks.

Springhouse answered 13/2, 2011 at 10:10 Comment(1)
Refer to below link for the solution: #10598331Albanian
F
2

If I recall correctly, the stock JDK used gtk1, but ubuntu uses gtk2 currently. I forget where but i've come across gtk2 for java somewhere. Google? Probably not what you were hoping for, sorry.

Fineberg answered 13/2, 2011 at 12:0 Comment(2)
Searching this did help, I ran into this: code.google.com/p/gtkjfilechooser . Not sure how I can make this perform cross-platform, but I'll look more into it. Thanks for your help.Springhouse
You could probably do what jzd was suggesting you do with nimbus and add this as a seperate lib in your project and only use the look on systems that want a gtk native look.Fineberg
S
1

You might see if FileDialog is any more appealing; here's an example.

FileDialog

Swiercz answered 13/2, 2011 at 12:1 Comment(1)
This is not that appealing to me, but thanks for the tip anyway.Springhouse
T
1

The Nimbus look and feel has a decent file chooser. Although this will affect your entire application, you might like the look.

Also you can build your own file chooser if needed.

Tyrolienne answered 13/2, 2011 at 14:6 Comment(2)
Nimbus was only added in Java 6 update 10, I think. I'm trying to stay away from forcing specific Java versions (might be able to do a fall-back somehow?), but I'll definitely look into this, thanks.Springhouse
Before it was included in the JRE it was a separate library that you would include in your project. That would work for older versions of Java.Tyrolienne
A
0

You can also use SWT instead of swing.

Does Swing support Windows 7-style file choosers?

The following code is from above link

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class SWTFileOpenSnippet {
    public static void main (String [] args) {
        Display display = new Display ();
        Shell shell = new Shell (display);
        // Don't show the shell.
        //shell.open ();  
        FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
        String [] filterNames = new String [] {"All Files (*)"};
        String [] filterExtensions = new String [] {"*"};
        String filterPath = "c:\\";
        dialog.setFilterNames (filterNames);
        dialog.setFilterExtensions (filterExtensions);
        dialog.setFilterPath (filterPath);
        dialog.open();
        System.out.println ("Selected files: ");
        String[] selectedFileNames = dialog.getFileNames();
        for(String fileName : selectedFileNames) {
            System.out.println("  " + fileName);
        }
        shell.close();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }
}
Albanian answered 27/4, 2013 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.