[REVIEW REQUEST] Support for customising the TableColumn header area

Jonathan Giles jonathan.giles at oracle.com
Mon Mar 12 17:51:03 PDT 2012

Hi all,

An area that I'm planning to improve in JavaFX 2.2 is to do with 
providing API around interacting with the header area of the TableView 
control. This is also known as RT-14909 [1].

The main use cases here (that have been expressed to me - if you have 
others let me know!) are the following:

1) Putting a graphic in the header area, with no text beside it. This 
would allow for the common UI pattern you see in mail programs and other 
applications where there are narrow columns. For example, Thunderbird 
has a 'junk status' column that shows a flame in the header area, and no 
text. This is because the visuals in this content area for this column 
are just a circle for toggling true or false, and any text in the column 
header would either make the column too wide, or result in the text 
being truncated.

2) Inserting buttons that provide additional functionality. For example, 
a MenuButton may be placed in the header to allow for the user to choose 
from a set of filter rules, etc.

3) Easily attaching a context menu for column-specific actions.

I think providing API to deal with these use cases is quite important, 
and have a first draft patch attached to RT-14909 for your reading 
pleasure. I've created two patches, one which only shows the public API 
changes, and the other that shows all changes. As I note later in the 
Jira thread, I'm not overly happy with certain parts of the proposed 
API, but I wanted to make what I do have public so that any feedback or 
use cases can come in early. In other words, this is more of a straw man 
proposal, and I really welcome your feedback.

An example use of this new API to place an image in the header is the 
following code:


Of course, as with all references to 'graphic' in the Controls API, this 
can be any Node, and it will be fully interactive (that is, it won't be 
'drawn' into the header, it'll be a true part of the scenegraph). This 
means you can use the same API above to put a Button or any other control:

    countryCol.getHeader().setGraphic(new Button("Interactive Button"));

For the context menu use case, this can be achieved as following:

    ContextMenu menu = new ContextMenu(new MenuItem("Reset column

Finally, you can also overwrite the sort node. For example, the 
following code crudely replaces the normal TableView sort arrow with a 
green or red 10x10 pixel rectangle, based on the sort order. If no 
sortNode is set, the default one is used instead.

    Rectangle rect = new Rectangle(10, 10);
    rect.fillProperty().bind(new ObjectBinding<Paint>() {
         { bind(countryCol.sortTypeProperty()); }

         @Override protected Paint computeValue() {
             return countryCol.getSortType() ==
    TableColumn.SortType.ASCENDING ? Color.RED : Color.GREEN;

Once again, thanks for your consideration, and I look forward to your 

[1] http://javafx-jira.kenai.com/browse/RT-14909


More information about the openjfx-dev mailing list