2

I'm currently working on a GUI-heavy application, one that uses JInternalFrame to have multiple smaller windows open in one instance of JDesktopPane, and I'm trying to personalize the look of the Nimbus Look and Feel. I can easily change Primary and Secondary colours, but I'm running into trouble when I try to change individual components, the current culprit being JLabel text.

This is the method I'm using to both set the LnF, and customize it:

(Apologies in advance if I bollox up the codeblock)

protected static void GUIStyle() throws Exception
{
    //Setting GUI styling

    UIManager.put("nimbusBase", new Color(255, 128, 0));
    UIManager.put("control", new Color(65, 105, 255));
    //UIManager.put("textForeground", Color.WHITE);
    try 
    {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) 
            {
                if ("Nimbus".equals(info.getName())) 
                {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
    }
    catch (Exception e) 
    {
       UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    }

    UIManager.getLookAndFeelDefaults().put("MenuItem[Enabled].textForeground", Color.WHITE);
    UIManager.getLookAndFeelDefaults().put("MenuBar:Menu[Enabled].textForeground", Color.WHITE);
}

Now, I'm trying to make the text on every JLabel in the application white, but I can't seem to pin down the specific component that does it, even with this handy list.

Adding UIManager.getLookAndFeelDefaults().put("InternalFrame.foreground", Color.WHITE); didn't work.

Neither did UIManager.getLookAndFeelDefaults().put("Label.foreground", Color.WHITE);

I'm stumped. It's obviously doable, because I can change all of the text to white by adding UIManager.put("text", Color.WHITE); before I set the Look and Feel. But given the circumstances, I only need the JLabel text to be white, not absolutely every piece of text.

Thank you in advance. If you could explain why exactly I'm having trouble with this (or point me to the proper resource explaining why) I'd love to see it. I'm having similar problems with other components as well, but I'm hoping that if I can get to the bottom of this one, I can figure out the others.

South
  • 21
  • 2
  • And I managed to bollox up the codeblock. – South Sep 19 '13 at 06:47
  • Try changing the `UIManager` values AFTER you've installed the look and feel... – MadProgrammer Sep 19 '13 at 06:48
  • I've read from a few other threads that you should change overall UIManager values before you install it using UIManager.put(), and then you should change specific components using UIManager.getLookAndFeelDefaults().put() after. Given that my nimbusBase, control and text.foreground changes to UIManager all work before installing it, and that my changes to the Menubar text after installing it work fine, that doesn't seem to be the issue. – South Sep 19 '13 at 06:54
  • Nimbus may be expecting a `ColorUIResource` instead of a `Color` – MadProgrammer Sep 19 '13 at 07:01
  • right see that as bug, you can to change colors only for `JLabel.setEnabled(false);` – mKorbel Sep 19 '13 at 07:04
  • @MadProgrammer, ColorUIResource and Color seem to work equally well when setting primary and secondary values, but neither work when trying to change the JLabel text colour. @mKorbel, you mean that you can only currently change the colour for the JLabel component when its enabled state is set to false (as in, "disabled" JLabel text)? I think I'm going to take a look at the Nimbus UI manager and see how it handles `UIManager.put("text", X)`. – South Sep 19 '13 at 19:17

0 Answers0