1

我正在使用RSyntaxTextArea最终从JTextArea. 当我将外观更改为 时Nimbus,文本区域不会像其他看起来不太好的 GUI 一样受到影响。

这是Nimbus我使用的主题代码:

import javax.swing.*;
import java.awt.*;

import static javax.swing.SwingUtilities.updateComponentTreeUI;
import static javax.swing.UIManager.*;

public class SwingLookAndFeel
{
    static void setDarkNimbusLookAndFeel(JFrame frame) throws Exception
    {
        put("control", new Color(128, 128, 128));
        put("info", new Color(128, 128, 128));
        put("nimbusBase", new Color(18, 30, 49));
        put("nimbusAlertYellow", new Color(248, 187, 0));
        put("nimbusDisabledText", new Color(128, 128, 128));
        put("nimbusFocus", new Color(115, 164, 209));
        put("nimbusGreen", new Color(176, 179, 50));
        put("nimbusInfoBlue", new Color(66, 139, 221));
        put("nimbusLightBackground", new Color(18, 30, 49));
        put("nimbusOrange", new Color(191, 98, 4));
        put("nimbusRed", new Color(169, 46, 34));
        put("nimbusSelectedText", new Color(255, 255, 255));
        put("nimbusSelectionBackground", new Color(104, 93, 156));
        put("text", new Color(230, 230, 230));

        for (LookAndFeelInfo[] info : getInstalledLookAndFeels())
        {
            if ("Nimbus".equals(info.getName()))
            {
                setLookAndFeel(info.getClassName());
                break;
            }
        }

        refreshFrame(frame);
    }

    private static void refreshFrame(JFrame frame)
    {
        if (frame != null)
        {
            updateComponentTreeUI(frame);
            // frame.pack();
        }
    }
}

我想知道UIManager修改文本区域背景颜色还需要哪些键,例如通过将JTree左侧的紫色设置为背景颜色而不是白色?

UIManager我找到的键列表,但它们中的任何一个在这种情况下甚至有用吗?

4

1 回答 1

2

这里描述了如何专门为RSyntaxTextArea. 使用提供的dark.xml工作正常:

private void changeStyleViaThemeXml() {
  try {
     Theme theme = Theme.load(getClass().getResourceAsStream(
           "/org/fife/ui/rsyntaxtextarea/themes/dark.xml"));
     theme.apply(textArea);
  } catch (IOException ioe) { // Never happens
     ioe.printStackTrace();
  }
}
于 2018-01-06T15:26:41.177 回答