How to set alignment of TableView

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set alignment of TableView

ninjathehunter
Hi

I created a table view that looks like this:

<StackPane>
        <TableView bxml:id="tableView" selectMode="multi" styles="{showHorizontalGridLines:true, includeTrailingVerticalGridLine:true}">
            <columns>
                <TableView.Column name="rowid" width="100" headerData="Row ID"/>
                <TableView.Column name="customer" width="100" headerData="Customer"/>
                <TableView.Column name="product" width="100" headerData="Product"/>
            </columns>
        </TableView>
    </StackPane>

However, the tltle of each column is by default left aligned. How can I change the alignment of a table column name and column data?

Thank you very much.
Reply | Threaded
Open this post in threaded view
|

RE: How to set alignment of TableView

Roger Whitcomb-2
So, the header data is rendered with an instance of a TableViewHeaderDataRenderer (by default), which itself is a subclass of BoxPane and contains an Image and a Label component as children.  There are two relatively easy ways to center things:
1. Get the default header data renderer and set the horizontal alignment style to "center".
2. Subclass the default TableViewHeaderDataRenderer yourself and set the style in your constructor, then set this modified renderer as the header data renderer on the TableView.

If you need actual code for either of these methods, I could do that, but thought you might want to take a crack yourself....

In general, using one of these two methods works for (almost?) all rendering type issues in Pivot (things like changing alignment, wrapping, increasing padding, or spacing, or setting special attributes on text).  All the default renderers are just made up of simple containers and components, but which implement the specific "render" method needed for the component.  If you look at the source code for any of these *Renderer.java files you should be able to see what I mean.

The third option is to implement a completely new renderer on your own and set it as the renderer on your object.  I've never found that to be necessary, personally, but it could be done.  Almost always you can either subclass the default implementation (and you usually just have to write a custom constructor and set some styles or attributes there), or you can just get the default instance and do the same thing in your own code.

HTH,
~Roger

-----Original Message-----
From: ninjathehunter [mailto:[hidden email]]
Sent: Tuesday, August 05, 2014 2:04 PM
To: [hidden email]
Subject: How to set alignment of TableView

Hi

I created a table view that looks like this:

<StackPane>
        <TableView bxml:id="tableView" selectMode="multi"
styles="{showHorizontalGridLines:true,
includeTrailingVerticalGridLine:true}">
            <columns>
                <TableView.Column name="rowid" width="100" headerData="Row ID"/>
                <TableView.Column name="customer" width="100"
headerData="Customer"/>
                <TableView.Column name="product" width="100"
headerData="Product"/>
            </columns>
        </TableView>
    </StackPane>

However, the tltle of each column is by default left aligned. How can I change the alignment of a table column name and column data?

Thank you very much.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/How-to-set-alignment-of-TableView-tp4022988.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.