java - JFileChooser 中的 UIManager 颜色

标签 java swing jfilechooser nimbus uidefaults

我使用的是 Nimbus Look and Feel,它的颜色只有 3 处变化:

UIManager.put("nimbusSelection", new Color(164,164,164));
UIManager.put("nimbusSelectionBackground", new Color(214,217,223));
UIManager.put("nimbusSelectedText", Color.BLACK);

我的 FileChooser 看起来像这样:

enter image description here

因此,所选文件的名称显示为白色且看起来很糟糕,而且在组合框中选择的文件类型也会发生这种情况。我想将其更改为黑色,但 nimbusSelectedText 已经是黑色并且无法正常工作。

我还查看了 http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary 上的 Nimbus Defaults 指南。我在 FileChooser 或 Combobox 中看不到任何参数来解决这个问题。

对识别必要参数有什么帮助吗?谢谢

最佳答案

JFileChooser是化合物JComponent ,您可以提取 JButtonsJToggleButtonsJScrollPane with JViewPort that contains JList ,请下载 Darryl 的 Swing Utils ,阅读描述,然后运行(Darryl 的)代码,结果是选择 JList 或 JTable(我对此投票)

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.plaf.metal.MetalButtonUI;

public class CrazyFileChooser {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                new CrazyFileChooser().makeUI();
            }
        });
    }

    public void makeUI() {
        JFileChooser chooser = new JFileChooser();
        for (AbstractButton button : SwingUtils.getDescendantsOfType(AbstractButton.class, chooser)) {
            button.setUI(new XORButtonUI());
        }
        for (JList list : SwingUtils.getDescendantsOfType(JList.class, chooser)) {
            list.setBackground(Color.PINK);
        }
        chooser.showOpenDialog(null);
    }
}

class XORButtonUI extends MetalButtonUI {

    @Override
    public void paint(Graphics g, JComponent c) {
        g.setXORMode(Color.YELLOW);
        super.paint(g, c);
    }
} 

关于java - JFileChooser 中的 UIManager 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6758719/

相关文章:

java - 从 spring Controller 发布到不同的 URL

java - Hibernate 没有在 pojo 的父类中获取继承属性

java - 如何在Java中连接后设置XML字符串?

java - JTable、TableModel 和 TableData 之间的关系

java - 将 JFileChooser 添加到 Eclipse Window Builder

java - JFileChooser 选择目录但显示文件

java - 使用 JFileChooser 获取目录的路径

java - 谷歌应用引擎: Orchestrating Multiple Apps to Deliver a Composite Service

java - 删除最后一个字符/行

java - JFrame 中的错误