View RSS Feed

Java Swing

Dynamically Changing the Default Look-and-Feel

Rate this Entry
by , 04-26-2012 at 08:41 PM (1290 Views)
When look and feel is being set programmatically by the Swing application as it has been discussed above, the ideal place considered is before instantiation of the Swing components. This happens as the particular LookAndFeel is made current default by UIManager.setLookAndFeel() method, by initializing or loading the LookAndFeel instance, however components are not automatically caused to make their look & feel changed.


It shall be noticed that UI delegates are initialized by the components at construct time, hence, when changes are made in current default after their construction, they wouldn’t get updated with UIs automatically. This is in hand of program to do the dynamic switching by containment hierarchy traversing and components updation individually.
It is possible to update look & feel at anytime so that for matching the current default, by updateUI() method invoke, that using these given static methods present at UIManager to obtain the proper UI delegate.
Java Code:
   public static ComponentUI getUI(JComponent c)
For instance, the updateUI() implementation for JScrollBar is as following:
Java Code:
public void updateUI() {
   setUI((ScrollBarUI)UIManager.getUI(this));
}

Submit "Dynamically Changing the Default Look-and-Feel" to Facebook Submit "Dynamically Changing the Default Look-and-Feel" to Digg Submit "Dynamically Changing the Default Look-and-Feel" to del.icio.us Submit "Dynamically Changing the Default Look-and-Feel" to StumbleUpon Submit "Dynamically Changing the Default Look-and-Feel" to Google

Comments