styles

XUI styles are used to define application-wide styles which can be applied to screen components. They work in much the same way as cascading style sheets do in HTML. The file which defines the application's styles are specified in the startup properties file with the StyleFile property as in listing 1.

Listing 1 - Setting the style file
StyleFile=styles.xml

An example style file is shown in listing 2. If you look at the panel style you can see that it defines a font_face and a font_size even though the panels will not use these styles directly. The prompt and data styles which are embedded within the panel style inherit the font styles from the panel style.

Listing 2 - A sample styles file
    
        
        
        
            
        
    

A page which uses the styles is shown in listing 3. The styles are applied to the components by setting the style attribute. If you need to use one of the embedded styles you can use the syntax panel/data

Listing 3 - A page using the styles file

    
        

The resulting page can be seen in figure 1

Figure 1 - The styled page

The styles which can be set within a XUI application are shown in listing 4.

Listing 4 - Available styles
color_back The background colour of the component
color_fore The foreground colour of the component
font_face The name of the font for components which contain text
font_size The size of the font for components which contain text
font_weight 1 if the font should be bold or 0 if it is to be normal.
font_italic 1 if the font should be italic or 0 if it is to be normal.

If you need to use styles from your Java code you can access them via the XStyleManager class. Listing 5 shows you how to set the style of a component in an XPage

Listing 5 - Accessing the XStyleManager
XStyleManager styMgr = XProjectManager.getStyleManager();
XStyle style = styMgr.getStyle( "panel/data" );
XStyleFactory styleFact = ( XStyleFactory )getComponentFactory();
XLabel firstnameLabel = ( XLabel )findcomponent( "firstname" );
styleFact.applyStyle( firstnameLabel, style );