javaswinglook-and-feeljtabbedpaneuimanager

How to change the background color of JTabbedPane at runtime?


I've found a lot of examples that change the background color of JTabbedPane using either setBackgroundAt() and UIManager.put("JTabbedPane...") .

However, I want to create an onclick event on a checkbox that changes the background color to green when you select it, and back to default when you unselect it.

I haven't been able to make that work using the above methods.

Any ideas?

PS: I can change the foreground color by using setForgroundAt(), but not the background for some reason.


Solution

  • LAFs are free to ignore custom settings of some (visual only? don't know) JComponent properties, as documented f.i.:

    It is up to the look and feel to honor this property, some may choose to ignore it.

    So the outcome is highly LAF-dependent (Worksforme in Metal and Motif, not in Nimbus/Win) No easy and safe way around (except tweaking the ui delegate, which isn't a real option)