Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change java swing look and feel without application restart?

is there a specific way to change the look and feel of a swing application without needing to restart the application every time the LAF got changed by the user?

im looking for a solution where one can select the LAF from a configuration dialog and it changes directly on apply without having to fall back to telling the user to restart the application.

currently i remember the selected LAF in a properties file and set it on startup before any window has been opened.

like image 334
subes Avatar asked Sep 22 '10 10:09

subes


Video Answer


1 Answers

From the Java tutorial:

You first need to set the new look and feel by calling UIManager.setLookAndFeel:

UIManager.setLookAndFeel(lnfName);

Then, in order to make existing componentes reflect the new look and feel, call the SwingUtilities.updateComponentTreeUI method on each top-level container (dialogs, frames..). You might also wish to resize each top-level container to adapt to changes in the size of its contained components:

SwingUtilities.updateComponentTreeUI(frame);  // update components
frame.pack();                                 // adapt container size if required
like image 142
Grodriguez Avatar answered Sep 29 '22 10:09

Grodriguez