|
Helping ordinary people create extraordinary websites! |
Advanced SynthBy Michael Abernethy2005-04-16
Changing a Color and Font The first step in creating the look and feel for the demo application is to set the default colors and fonts. You'll make the white Aharoni font the default font for every component that doesn't specifically set it otherwise. You can place the XML to change a font anywhere inside the <style> tag. You embed the color inside a <state> tag. I'll discuss the <state> tag more later in this article, but it's enough to understand now that a simple <state></state> tag with no attributes encompasses every state, which is what you need here. The color tag itself requires two attributes: • value can be any String representation of the java.awt.Color constants (for example, RED, BLUE), or it can be the hex representation of a color preceded by a "#" (for example, #669966). • type describes which area's color the file should set. The choices are BACKGROUND, FOREGROUND, TEXT_FOREGROUND, TEXT_BACKGROUND, and FOCUS. The font tag has two required attributes and one optional one. They map directly to the three parameters in the java.awt.Font class: • name: The font's name (for example, Verdana, Arial). • size:The size in pixels. • style: Leaving out this optional tag results in a normal-looking font. Other options include BOLD and ITALIC. You can also specify a bold italic font by putting a space between the two attributes: BOLD ITALIC. (This technique for combining attributes holds true for all attributes in the Synth XML file). Finally, instead of binding this style to each JLabel and each JButton, you can bind it to every component in the application, by using the .* wildcard. This wildcard tells the Synth look and feel to give every component a default white Aharoni font. Listing 3 shows the complete XML code for setting the components' font and color: Listing 3. Changing multiple components' fonts and colors <style id="default"> Tutorial Pages: » Custom UIs are a Breeze with the Newest Swing Look and Feel » Beauty's Only Skin Deep » Synth Basics » Demo Application » Changing a Color and Font » Using Images » Handling Different States » Working with Custom Painters » More-Advanced Settings » Examining Synth Performance, Reliability, and Efficiency » Conclusion » Resources First published by IBM DeveloperWorks |
|