How to disable the reordering of table columns in tableView?
Asked Answered
J

2

5

Trying to figure out on how can i disable the reordering of table columns in javafx 2?

Joktan answered 2/1, 2013 at 4:15 Comment(0)
J
9

Here's the solution:

tblView.getColumns().addListener(new ListChangeListener() {
        @Override
        public void onChanged(Change change) {
          change.next();
          if(change.wasReplaced()) {
              tblView.getColumns().clear();
              tblView.getColumns().addAll(column1,column2...);
          }
        }
    });
Joktan answered 2/1, 2013 at 4:15 Comment(4)
I think there should be some way to disable the column reordering behaviour via an API on the TableView class, you might want to also log a feature request against the JavaFX runtime project.Audiphone
@Audiphone So, it's been 1 year, any sign of an improved API method to lock the columns ?Hesperus
Feature request RT-26283 "Support "locking" columns (and rows) in TableView" was created. There has been no progress made on it and the request is currently not scheduled. The feature request was accepted, so a patch request to openjfx to add the feature would probably be accepted.Audiphone
thats not a solution to just delete every column and add them again.Noh
I
3

After much waste of time, I've found the following, very simple, solution:

TableHeaderRow header = (TableHeaderRow) myTableView.lookup("TableHeaderRow");
header.setMouseTransparent(true);
Irruption answered 27/9, 2017 at 16:57 Comment(1)
Like a charm in Java 8.Lani

© 2022 - 2024 — McMap. All rights reserved.