Background:
From the documentation, the method SwingUtilities.updateComponentTreeUI()
ask to each component in the tree (What tree?) to update their own UI properties calling the method updateUI()
.
SwingUtilities.updateComponentTreeUI()
is strictly recommended to be called after we set the LAF, calling the method: UIManager.setLookAndFeel(LAFClassName)
, otherwise the LAF theme could not be applied to some components and, worst, some components could not be redesigned (and some exceptions could be thrown?).
I am new to this kind of things and I discovered the method SwingUtilities.updateComponentTreeUI()
after the discover of the more suggestive UIManager.setLookAndFeel(LAFClassName)
method.
Before discovering SwingUtilities.updateComponentTreeUI()
I had been having some problems/Exceptions/NullPointerExceptions, and the truth is that I really wasn't understanding the reason of them until I didn't discover the SwingUtilities.updateComponentTreeUI()
method, which made me understand that some components in the tree could not be updated to the new LAF.
Concrete/real problem:
For instance, if I have a
subJFrame
(instantiated dynamically or triggered by an ActionEvent (click) in the
mainJFrame
), where I set the look and feels properties, and then I call SwingUtilitiesupdateComponentTreeUI()
passing to it a reference to the mainJFrame
:
SwingUtilities.updateComponentTreeUI(mainJFrame)
,
is this last one going to update all its sub-components/subJFrames (and hence updates the subJFrame
where I set the LAF) ?
This is not a trivial question (also keeping in my mind what the documentation says), because I call the UIManager.setLookAndFeel(LAFClassName)
method in the subJFrame
(what actually this call does?) and then I call SwingUtilities.updateComponentTreeUI()
method passing to it a reference to the mainJFrame
, so what LAF theme is going to be applied to all the sub-components of the mainJFrame
? And if some of the sub-components/subJFrames haven't been initialized yet?