Example: Specifying a Font Color for a Company Name

Suppose you have a crosstab, in which a Vendor dimension is displayed, and Oracle is one of the vendors. This example sets the font color for Oracle to red.

This example uses the following:

Example code

The following code creates the DiscriminatorRule, the RuleBundle, and the Vector for rule bundles. Then it sets the Vector of bundles in the CrosstabStyleManager.


//create a ViewStyle ViewStyle vs_redFont = new ViewStyle(); //Set the font color vs_redFont.setForeground(Color.red); //Create a discriminator that specifies when to display the item in red //First, create a QDR that specifies Oracle as the vendor QDR qdr_Oracle = new QDR("XP_MEASUREDIM", "VENDOR", "ORACLE"); //Then, create the QDRDiscriminator //This discriminator specifies that, in the formatted item, the //vendor must be Oracle. QDRDiscriminator dsc_Oracle = new QDRDiscriminator(qdr_Oracle, QDRDiscriminator.SUPERSET); //Create a DiscriminatorRule DiscriminatorRule dr_redOracle = new DiscriminatorRule(); //Set the discriminator, to tell when the rule should apply dr_redOracle.setDiscriminator(dsc_Oracle); //Set the ViewStyle (mergeable object), //to tell what formatting should be applied dr_redOracle.setFixedMergeable(vs_redFont); //Put the rule in a rule bundle RuleBundle rb_VendorStyles = new RuleBundle(); //Add the discriminator rule rb_VendorStyles.addRule(dr_redOracle); //Create a vector for the bundle, and add the bundle Vector rbVector = new Vector(); rbVector.addElement(rb_VendorStyles); //Get the rules style manager for the crosstab //assumes that the crosstab you want is "myCrosstab" GridViewHeaderRuleStyles manager = myCrosstab.getGridViewHeaderStyleManager(); //Add our rule bundle vector to whatever the manager has rbMgrBundle = manager.getBundles(); if (rbMgrBundle == null){ manager.setBundles(rbVector); } else{ rbMgrBundle.addElement(rb_VendorStyles); //you must set this so the manager knows to refresh manager.setBundles(rbMgrBundle); }