Java Nimbus Look & Feel RSyntaxTextArea Background Color

1k views Asked by At

I'm using RSyntaxTextArea which ultimately extends from JTextArea. When I change the look and feel to Nimbus, the text area is not affected the same way as the rest of the GUI which doesn't look nice.

This is the Nimbus theme code I used:

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();
        }
    }
}

I wonder which UIManager keys are needed to modify the text area background color as well e.g. by setting the purple color from the JTree on the left as background color instead of white?

Here is a list of UIManager keys I found but are any of them even helpful in this situation?

1

There are 1 answers

0
BullyWiiPlaza On BEST ANSWER

Here is described how to use themes specifically for RSyntaxTextArea. Using the provided dark.xml works fine:

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();
  }
}