有没有办法改善 Ubuntu 下 JFileChooser 的外观?

发布于 2024-10-17 16:39:29 字数 556 浏览 7 评论 0原文

我一直在制作一个使用 JFileChooser 的程序。我已经设置了应用程序

UIManager.getSystemLookAndFeelClassName()

几乎适用于 Ubuntu 下的所有内容。到目前为止我遇到的唯一问题是 JFileChooser 看起来非常糟糕: JFileChooser with SystemLookAndFeel

有没有办法让它看起来像 Ubuntu 中的默认文件选择器? IE。 所需文件选择器对话框

我尝试过使用

UIManager.getCrossPlatformLookAndFeelClassName()

这使得 JFileChooser 对话框看起来更好,但仍然不是本机外观,并且它也破坏了应用程序的其余部分的感觉。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

聆听风音 2024-10-24 16:39:47

您还可以使用 SWT 代替 swing。

Swing 是否支持 Windows 7 样式文件选择器?

以下内容代码来自上面的链接

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

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 ();
    }
}
孤君无依 2024-10-24 16:39:45

Nimbus 的外观和感觉有一个不错的文件选择器。尽管这会影响您的整个应用程序,但您可能会喜欢这种外观。

如果需要,您还可以构建自己的文件选择器。

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.

冰葑 2024-10-24 16:39:43

您可能会看到 FileDialog 更具吸引力;这是一个示例

文件对话框

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

FileDialog

旧时光的容颜 2024-10-24 16:39:40

如果我没记错的话,原生 JDK 使用的是 gtk1,但 ubuntu 目前使用的是 gtk2。我忘了在哪里,但我在某个地方遇到过 gtk2 for java 。谷歌?可能不是你所希望的,抱歉。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文