开发者

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

开发者 https://www.devze.com 2023-02-10 00:36 出处:网络
I\'ve been making a program that uses a JFileChooser. I\'ve set the application up with UIManager.getSystemLookAndFeelClassName()

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:

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

Is there a way 开发者_如何学JAVAto make this look like the default file chooser in Ubuntu? ie.

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

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.


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.


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

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


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.


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 ();
    }
}
0

精彩评论

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