Javafx : Restrict Column rearrangement on drag and drop -
in tree table view, can re-arrange columns dragging column headers. want restrict user dragging first column alone. means first column should first column time.
is possible?
thanks in advance.
this simple example storing column arrangement in temporary list , when ever trying move or replace first column resetting column arrangement.
!change.getlist().get(0).equals(col1)
checks if col1
still @ first location after change. if not, replace old list.
mcve
import javafx.application.application; import javafx.collections.fxcollections; import javafx.collections.listchangelistener; import javafx.collections.observablelist; import javafx.scene.scene; import javafx.scene.control.tablecolumn; import javafx.scene.control.tableview; import javafx.stage.stage; public class fixfiestcolumntable extends application { public static void main(string[] args) { launch(args); } @override public void start(stage stage) { final tableview tableview = new tableview(); tablecolumn col1 = new tablecolumn("col 1"); tablecolumn col2 = new tablecolumn("col 2"); tablecolumn col3 = new tablecolumn("col 3"); tableview.getcolumns().setall(col1, col2, col3); tableview.getcolumns().addlistener(new listchangelistener() { public observablelist<tablecolumn> templist = fxcollections.observablearraylist(); @override public void onchanged(change change) { change.next(); if (change.wasreplaced() && !change.getlist().get(0).equals(col1)) { tableview.getcolumns().setall(templist); } templist.setall(change.getlist()); } }); stage.setscene(new scene(tableview)); stage.show(); } }
Comments
Post a Comment