I need to show some sort method(for example BubbleSort) working and replacing bars to each other. I want to do it step by step. So in every element changing iteration I am also changing bar's places and use method layout() to show changes. However, changes are shown only after this sort method. I want to replace bars step by step and show that probably with some little delay(Thread.sleep(100);). Every bar in chart is associated with element in array_tmp.
How can I do that?
public void sortBubble(){
int n = array_tmp.length;
String temp;
XYChart.Data getChart1;
XYChart.Data getChart2;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(array_tmp[j-1].length() > array_tmp[j].length(){
getChart1 = barChart.getData().get(j - 1).getData().get(0);
getChart2 = barChart.getData().get(j).getData().get(0);
barChart.getData().get(j - 1).getData().remove(0);
barChart.getData().get(j).getData().remove(0);
barChart.layout();
barChart.getData().get(j - 1).getData().add(0, getChart2);
barChart.getData().get(j).getData().add(0, getChart1);
temp = array_tmp[j-1];
array_tmp[j-1] = array_tmp[j];
array_tmp[j] = temp;
}
}
}
}
You can use Animations, especially Transitions.
Here is a short example moving bars in a BarChart.
If you don't like the animation, just use:
bar.getNode().setTranslateX(xValueToGo);
PauseTransition is usefull for non ui-blocking delays: