VwpFAQAlignNumerickeytoRight

How do I align numeric keys to the right in a table?


Problem

I would like to align numeric colums to right in my table.

tc.setAlign ( null ); tc.setAlignKey ( fieldKey );

Where tc is a TableColumn, does not work. How to set the alignment in a variable Table ?

Solution

This is a known issue in VWP. To work around this issue you can use the following:


MyDataProvider rdp = getSessionBean ().getMyDataProvider ();
if ( render ) {
    FieldKey fieldKey = rdp.getFieldKeyForColumn ( c );
    // Set alignment.
    String result = null;
    Class type = rdp.getType ( fieldKey );
    if (type != null
       && (type.equals (Character.class) || type.equals (String.class))) {
   result = "left";
    } else if (type != null
       && ( java.util.Date.class.isAssignableFrom ( type ) || Number.class.isAssignableFrom ( type ))) {
   result = "right";
    } else if (type != null && type.equals (Boolean.class)) {
   result = "center";
    } else {
   // Note: Select columns also default to "left".
   result = "left";
    }
    tableColumn.setAlign ( result );

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo