Make your own theme
You have seen the last page in this article in which we attempt to change the appearance of chosen java L&F feel so that it looks and behaves the way we want it to. In the previous steps we retrieved the defaults fonts, colors etc associated with each PLAF and displayed them in a human readable form. Now it's time to see how we can assign new values to them.
The following code sample demonstrates how some of the properties can be changed. You will be able to set different values or change other properties when you download and compile the code. The colors are intentionally made to clash so that it's easy for you to spot the difference from the original. Colors are not the only things that are being changed and you may need to look closely to spot those differences.
UIDefaults def = UIManager.getLookAndFeelDefaults(); def.put("Button.background",new ColorUIResource(200,200,0)); def.put("ScrollBar.foreground",new ColorUIResource(200,0,0)); def.put("Table.focusCellBackground",new ColorUIResource(200,0,0)); def.put("TableHeader.foreground",new ColorUIResource(255,255,200)); def.put("TableHeader.background",new ColorUIResource(0,0,55)); def.put("Table.background",new ColorUIResource(240,240,240)); def.put("CheckBox.font",new FontUIResource("monospaced",Font.ITALIC,14)); def.put("TableHeader.font",new FontUIResource("serif",Font.BOLD,14));
If you think the color scheme in the applet above is terrible, let me assure you that it's intentional. The image on your left is a screen shot from the applet on the previous page before we made any modifications to the UIDefaults. You can compare it with the applet above to see how some of the colors etc have been changed. The changes will continue to be in effect even if you switch to a different look and feel (using the combobox at the top of the applet)
You can now download the code and try it out on your own