I know that there\'s a SwingUtilities.updateComponentTreeUI(Component c)
method but it doesn\'t work perfectly. For example, I have a JFileChooser
Calling SwingUtilities.updateComponentTreeUI(mainWindow)
will only update the Swing components in the Swing hierarchy under mainWindow
.
If you store the JFileChooser
somewhere in your code (e.g. in a field of a class) without showing the JFileChooser
the chooser will not be updated by the SwingUtilities.updateComponentTreeUI(mainWindow)
call. You can work around this by adding a listener to the UIManager
yourself and call SwingUtilities.updateComponentTreeUI(myStoredFileChooser)
from that listener when the look-and-feel is changed.
Make sure you do not create a memory leak with this, e.g. let that listener only have a WeakReference
to the JFileChooser
(as the lifetime of the UIManager equals the lifetime of the JVM)