java - How to most efficiently move multiple rectangles in JavaFX -
i have got listview has custom cellfactory defined.
these cell rows contain multiple rectangles represent shop open hours, customers times etc. gantt graph must react horizontal scrolling. every time horizontal bar moves, bars relocated.
the problem is slow.
public class shopcellworker extends listcell<shop> { ... public shopcellworker(scrollbar hbar, list<customervisit> visits) { this.hbar = hbar; visits.foreach(v -> { rectangle r = new rectangle(); ... setup ... rlist.add(r); } hbar.valueproperty().addlistener(new updatelistener()); } private class updatelistener implements changelistener { @override public void changed(observablevalue observable, object oldvalue, object newvalue) { rlist.foreach(rec -> { ... simple math determine position ... relocate(x, 3); }) } } }
is there trick make rendering faster?
try use group.
here draft version:
public class shopcellworker extends listcell<shop> { group rectgroup = new group(); public shopcellworker(scrollbar hbar, list<customervisit> visits) { visits.foreach(v -> { rectangle r = new rectangle(); ... setup ... rectgroup.getchildren().add(r); } hbar.valueproperty().addlistener(new updatelistener()); } private class updatelistener implements changelistener { @override public void changed(observablevalue observable, object oldvalue, object newvalue) { // have calculated new possition here rectgroup.settranslatex(calculatednewxpos); } } }
Comments
Post a Comment