Sep 22, 2008

Changing the Default UI Settings of Elements in Servoy

Look and Feel is used to set the general appearance of the Swings Component in java. Java Cross Platform Look & Feel is the default and this is the most portable also. You can design your own Look and Feel and apply your application as well. There are number of Free & Commercial Look and Feel available. You can google for the same or a good place to start with is from http://www.javootoo.com.

I just want to change the Default UI of the Swing Component. Then, I google through and found some of the facts that help me to play with the Default UI settings of the Swings Component. The javax.swing.UIManager class is used to handle most of the UI related aspects.

All the UI related properties are stored against keys. You can override or set the new value for the keys by using the javax.swing.UIManager.put(Object key, Object value) method.

You can get all the list of Keys & there default values by executing the below statements :

UIDefaults uiDefaults = UIManager.getDefaults();

Enumeration enum1 = uiDefaults.keys();
while (enum1.hasMoreElements())
{
Object key = enum1.nextElement();
Object value = uiDefaults.get(key);

System.out.println("Key : " + key + " - " + "Value : " + value);
}
This will print Keys And their default values.

You can change the Default UI Settings of Elements in Servoy by using the below code :

Let I want to change the Selection Background Color of the ComboBox to Pink. The below Code will do the same.

application.setUIProperty("ComboBox.selectionBackground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.PINK));

Here, the "ComboBox.selectionBackground" is the key responsible for Selection Background Color and the value is a Object of ColorUIResource.

Likewise, you can change the Default UI Settings by overriding the desired key values.

0 comments: