JFileChooser 中的 UIManager 颜色

发布于 2024-11-25 08:18:13 字数 755 浏览 4 评论 0原文

我正在使用 Nimbus 外观和感觉,其颜色仅发生 3 处变化:

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

我的 FileChooser 如下所示:

在此处输入图像描述

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

我还查看了 Nimbus 默认指南 http:// /download.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary 我在以下位置看不到参数FileChooser 或 Combobox 可以解决此问题。

有帮助确定必要的参数吗?谢谢

I'm using Nimbus Look and Feel, with only 3 changes at its colors:

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

My FileChooser looks like this:

enter image description here

So selected file's name appears in white and looks bad, and it also happens for the file type selected at the combobox. I want to change it to Black, but nimbusSelectedText is already black and is not working.

I also had a look at the Nimbus Defaults guide at http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary and i see no parameter at FileChooser or Combobox to fix this.

Any help identifying the necessary parameters? Thanks

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

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

发布评论

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

评论(3

送舟行 2024-12-02 08:18:13

JFileChooser 是复合的 JComponent,解压即可JButtonsJToggleButtons带有包含 JList 的 JViewPort 的 JScrollPane,请下载 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);
    }
} 

JFileChooser is compound JComponent, you can extract JButtons, JToggleButtons and JScrollPane with JViewPort that contains JList, please download Darryl's Swing Utils , read descriptions, then run (Darryl's) code, result is selection for JList or JTable (I voting for that)

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);
    }
} 
帅的被狗咬 2024-12-02 08:18:13

嗯,有一种方法可以做到这一点。您可以从 JFileChooser 获取 JList 并修改它:

public boolean getJList(Container c)
{
    Component[] cmps = c.getComponents();
    for (Component cmp : cmps)
    {
        if (cmp instanceof JList)
        {
            modifyJList((JList)cmp);
            return true;
        }
        if (cmp instanceof Container)
        {
            if(getJList((Container) cmp)) return true;
        }
    }
    return false;
}
private void modifyJList(JList list)
{
    // Here you can modify your JList
}

要使用它,只需调用 getJList()

JFileChooser chooser = new JFileChooser();
getJList(chooser);

Well, there is one way possible to do it. You can get the JList from your JFileChooser and modify it:

public boolean getJList(Container c)
{
    Component[] cmps = c.getComponents();
    for (Component cmp : cmps)
    {
        if (cmp instanceof JList)
        {
            modifyJList((JList)cmp);
            return true;
        }
        if (cmp instanceof Container)
        {
            if(getJList((Container) cmp)) return true;
        }
    }
    return false;
}
private void modifyJList(JList list)
{
    // Here you can modify your JList
}

and to use it, just call getJList():

JFileChooser chooser = new JFileChooser();
getJList(chooser);
岁吢 2024-12-02 08:18:13

我真的不知道,但是您是否尝试过设置此属性:

List.selectionForceground
List.selectionBackground

FileChooser 看起来非常像列表...


第二次尝试。也许这些设置有帮助:

controlHighlight
controlLHighlight

I really don't know, but have you tried setting this properties:

List.selectionForceground
List.selectionBackground

A FileChooser looks pretty much like a list...


Second try. Maybe settings these helps:

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