繁体   English   中英

JFileChooser上的系统外观布局,但具有灵气的外观和感觉主题

[英]System look and feel layout on JFileChooser but with nimbus look and feel theme

JFileChooser上的窗口外观和感觉布局比其他外观好很多,感觉就像灵气。

所以我正在寻找一种方法来获得系统外观和感觉的布局,但在顶部有nimbus或其他主题。

这可能吗? 如果是这样,怎么办呢?

这是可能的,虽然我不知道是否推荐。 我设法通过要求视图在除了最顶层的JFileChooser组件之外的所有组件上更新自己来实现它(因为这将用你不想要的Nimbus组件替换所有选择器组件)。

我认为这可能会或可能不会起作用,具体取决于Windows外观的内部结构。 它几乎依赖于由Swing组件构建的整个JFileChooser。 如果它被更改为使用更直接的本机渲染(即Java要求Windows绘制选择器的重要部分),它将无法工作。 不知道这个技巧与其他组件的效果如何。

无论如何,这段代码似乎适用于JDK 7:

package test;

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.plaf.nimbus.NimbusLookAndFeel; //Or use com.sun.... if you are using JDK < 7

public class LAFTester
{
    public static void main(String... args)
    throws Exception
    {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        JFileChooser chooser = new JFileChooser();
        chooser.updateUI(); //Create UI objects
        UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName()); //Now set look and feel
        //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); //works with metal as well
        refreshUI(chooser, false);

        chooser.showOpenDialog(null);
    }

    private static void refreshUI(JComponent c, boolean includeParent)
    {
        if (includeParent)
            c.updateUI();

        for (int i = 0; i < c.getComponentCount(); i++)
        {
            Component child = c.getComponent(i);
            if (child instanceof JComponent)
            {
                refreshUI((JComponent)child, true);
            }
        }
    }
}

我假设您正在讨论Windows文件选择器对话框左侧的面板,其中包含DesktopMy Computer My Documents图标?

好吧,我怀疑这可以做到,因为这是特定于LAF的。 这被添加到Windows LAF中,因为这是Windows平台文件选择的样子。 它不支持其他LAF。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM