I'm trying to create a JTabbedPane with markers for the tabs that need the user's attention. It is going to be used for a settings dialog.
This means the background color should be changeable dynamically and independent of tab selection.
The validation for the elements is working (e.g. red border around invalid textfields), but I have trouble to mark the containing tab by setting a background color. The code to find the containing tab and propagate the invalid state is ready. The only thing is: setBackgroundAt(index, Color);
has no effect at all.
I have verified that the statement is reached and the index is correct.
But nothing happens. Neither repaint();
nor SwingUtilities.updateComponentTreeUI(this);
did help.
I have found several examples of people giving different colors to different tabs. This is the one I started with: Colorize a tab in a JTabbedPane using java swing
But all of the examples I found set the color statically (before showing the JFrame) and what is even worse, the background color disappears for the selected tab.
As my application also allows to select the look & feel, the solution should be L&F independent.
BTW: A red border around the tab instead of a background will do too.