2

After some extensive search, I have not been able to figure out how to get the color shown in the image below pointed by the red arrow. The reason I want to get this color value is to set the pane background inside the JTabbedPane (blue arrow) with the same value, so there would be no difference between the two colors. On Windows, the color is white (red arrow), on Mac it's 230, 230, 230 RGB, and on Linux it depends on the GUI. So, by getting this value programatically, I wouldn't have to set it for each OS.

enter image description here

Any idea how to accomplish this? I've tried searching for 230, 230, 230 in UIManager.getDefaults() but there isn't such value.

Thanks in advance

rodd
  • 193
  • 1
  • 2
  • 11
  • 2
    Wouldn't the simplest solution be to just make your "pane inside JTabbedPane" nonopaque (`pane.setOpaque(false);`? This way, the background color of JTabbedPane would show through that pane, whichever platform this runs on? – Guillaume Polet Sep 19 '14 at 19:51
  • Otherwise, you should be able to use `UIDefaults.getDefaults().getColor("TabbedPane.background")` but I wouldn't recommend it, because it could fail on some L&F. It's much better to use the first solution suggested. – Guillaume Polet Sep 19 '14 at 20:02
  • For reference, the UI delegate's source is cited [here](http://stackoverflow.com/a/25728130/230513); this might be the color calculated by `fillTabWithBackground()`. – trashgod Sep 20 '14 at 01:10
  • @Guillaume Polet could you please post your first comment as the answer? This is the best solution I've found. Thank you. – rodd Sep 20 '14 at 04:00
  • @rodd Ok, wasn't completely sure and I couldn't test it because I don't have a Mac :-) – Guillaume Polet Sep 21 '14 at 18:38

1 Answers1

2

Consider simply setting the opacity of the contained panel to false. This should let the background color of the wrapping JTabbedPane reflect through that component and achieve the desired behaviour. Moreover this will work on all platforms and look and feels.

Something like:

pane.setOpaque(false);
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117