JavaFX, how to freeze the position of some columns in TableView

Luca picture Luca · Jul 17, 2013 · Viewed 9k times · Source

The idea is: on a TableView of N columns to have the first M columns always visible even when you use the horizontal scroller.

The only thing near my requirement is this Binding two tableviews together such that they scroll in sync. The idea to put side by side two tables is not the best by my point of view because

1) The sort of the column is partially indipendent between the two tables: if you use the same observableList the rows are sorted in both tables but it is not possible the sort on multiple columns where at least one column is not on the same table
2) There is no syncronous scroll with the mouse wheel or with the arrows keys

I know that, probably, I can cope with problems like these using EventHandlers and Listeners but I am hoping it is possible to use only one table.

So, the question is: are there any configurable properties on TableView or TableColumns to have the behaviour I am looking for?

Answer

Vishwanjali Jadhav picture Vishwanjali Jadhav · May 30, 2016

I am able to freeze columns in javafx table view. We need to create our custom table column class where in we will have two methods setFixed and isFixed which will be used to make some column as fixed.

Apart from this you need to create your own

  1. TableViewskin

  2. TableHeaderRow - basically in this class you need to override the getRootHeader() method

  3. NestedTableColumnHeader - In this class override layoutChildren() method and add new method to layout the fixedColumns
  4. VirtualFlow
  5. TableView - override createDefaultSkin() , add new booleanProperty showColumnHeaderand one ObservableArrayList for fixedTableColumn
  6. TableRow - Override createDefaultSkin()
  7. TableRowSkinBase - override layoutChildren() method to handle fixed columns.