JIMileChooser上的UIManager颜色

我正在使用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看起来像这样:

在此处输入图像描述

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

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

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

嗯,有一种方法可以做到这一点。 您可以从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); 

JFileChooser是复合JComponent ,您可以使用包含JList的JViewPort提取JButtons , JToggleButtons和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); } } 

我真的不知道,但你尝试过设置这个属性:

 List.selectionForceground List.selectionBackground 

FileChooser看起来非常像列表……


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

 controlHighlight controlLHighlight