I am using JavaFx, and I have an EventHandler that runs when a button is clicked. The Handler is supposed to 1) put a progress bar on the screen, and AFTERWARDS make a new window. The window takes a little while to create, so the progress bar is there to let people know that the program did not just freeze.
Here is the code that contains the EventHandler
public HBox SelectionSection(){ final HBox hb = new HBox();
GridPane grid = new GridPane();
grid.setAlignment(Pos.BASELINE_LEFT);
hb.setStyle("-fx-background-color: linear-gradient(#CEF5FD 0%, #1864E2 100%);");
hb.setPrefSize(350, HEIGHT);
Button done = new Button("Create Data");
final CheckBox ch1 = new CheckBox("Class Stats");
ch1.setSelected(true);
final CheckBox ch2 = new CheckBox("Class Chart");
ch2.setSelected(true);
final CheckBox ch5 = new CheckBox("Interactive Stats");
final CheckBox ch3 = new CheckBox("Objectives Summary");
final CheckBox ch4 = new CheckBox("part 4");
final JFXDragAndDrop JFX = this;
CheckBox sdf = new CheckBox();
done.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent arg0) {
if(dir!=null){
grid.getChildren().add(p1);
new Excel(JFX, dir, ch1.isSelected(), ch2.isSelected(), ch3.isSelected(), ch4.isSelected(), ch5.isSelected());
}
else{
Platform.runLater(new Runnable(){
public void run(){
JFX.createError(2);
}
});
}
}
});
GridPane.setConstraints(ch1, 7, 7, 1, 1,HPos.LEFT, VPos.CENTER);
GridPane.setConstraints(ch2, 7, 8, 1, 1,HPos.LEFT, VPos.CENTER);
GridPane.setConstraints(ch5, 7, 9, 1, 1, HPos.LEFT, VPos.CENTER);
GridPane.setConstraints(ch3, 7, 10, 1, 1,HPos.LEFT, VPos.CENTER);
GridPane.setConstraints(done, 7, 16, 1, 1,HPos.CENTER, VPos.CENTER);
GridPane.setConstraints(p1,7,15,1,1,HPos.CENTER,VPos.CENTER);
grid.getChildren().addAll(ch1,ch2,ch3,ch5,done);
hb.getChildren().add(grid);
return hb;
}
Here is a picture of what it should look like. The loading bar should pop up as soon as you click the 'done' button. Instead, it finishes running Excel() before the loading bar pops up.