0
private JDialog dialog;
private JTextArea text;
private JPanel buttons, filler;
private JRadioButton questions, list;
private ButtonGroup group;
private JButton confirm;

dialog = new JDialog(Main.masterWindow, lang.getString("newTitle"), true);
dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
dialog.setResizable(false);

text = new JTextArea();

//this works
text.setBackground(Color.RED);

//this both don't
text.setBackground((Color)UIManager.get("control");
text.setBackground(dialog.getContentPane().getBackground());

dialog.setVisible(true);

I am using Nimbus L&F, and "control" is the background color of my dialog. If I set any other color (red in this example) it shows, but if I set it to this one, it's stays white.

I don't have tis problem on default (metal) L&F...

What's the problem?

Ivan Karlovic
  • 221
  • 5
  • 14

2 Answers2

1

Try running the following code:

    System.out.println((Color)UIManager.get("control"));

This will print out what color exactly you are getting from the UIManager. Perhaps it is actually supposed to be white. Tell me what that prints

EDIT:

//this both don't
//text.setBackground(dialog.getContentPane.getBackground());

Well first off, you don't have () after getContentPane even though it is a method. Try doing it like this: text.setBackground(dialog.getContentPane().getBackground());

Alex Coleman
  • 7,216
  • 1
  • 22
  • 31
  • `javax.swing.plaf.ColorUIResource[r=214,g=217,b=223]` – Ivan Karlovic Sep 15 '12 at 16:14
  • Okay, I've fixed it with creating new color with those RGB valuse, but I don't understand why can't I fetch color from dialog background? In this case it's okay, but my dialogs background my be different, and I want the JTextArea to keep up, if I won't be able to access the color directly. – Ivan Karlovic Sep 15 '12 at 16:16
  • Nah, I just made a mistake here, it would return compiling error if I did it in Eclipse... – Ivan Karlovic Sep 15 '12 at 16:29
  • @Alex Coleman [Nimbus Defaults](http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#menubar) and [How To](http://stackoverflow.com/a/12382370/714968) – mKorbel Sep 15 '12 at 21:16
1

For some reason, it doesn't seem to like the ColorUIResource object the is returned from UIManager.get call. I can't see why, because it's derived from Color.

If you do something like

JDialog dialog = new JDialog((JFrame) null, "Help", true);
dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));

JTextArea text = new JTextArea(10, 10);

Color color = new Color(UIManager.getColor("control").getRGB()); // <-- Create a new color

text.setBackground(bg);

dialog.add(text);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);

This seems to work.

Should you have to do it. I don't think so, but every thing else I tried didn't work

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366