Answer the question
In order to leave comments, you need to log in
Why is ProgressBar not showing in JavaFX?
I want to add a ProgressBar to the login page to show something like loading.
My code below doesn't show the ProgressBar at all, but if I comment out the try&catch block, the ProgressBar is displayed.
What could be the problem?
public class LoginController {
@FXML
private TextField userNameField;
@FXML
private PasswordField passwordField;
@FXML
private Label errorLabel;
@FXML
private Button loginBtn;
@FXML
private ProgressBar loginProgressBar;
@FXML
void initialize() {
loginBtn.setOnAction(event -> {
loginProgressBar.setVisible(true);
loginProgressBar.setProgress(-1.0f);
String userName = userNameField.getText();
String password = passwordField.getText();
try {
if (authenticate(userName, password)) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/fxml/MainMenu.fxml"));
try {
loader.load();
} catch (IOException e) {
e.printStackTrace();
}
loginBtn.getScene().getWindow().hide();
Parent root = loader.getRoot();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
errorLabel.setText("");
} else {
errorLabel.setText("Неверные данные для входа");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
clearFields();
});
}
Answer the question
In order to leave comments, you need to log in
I suspect you are doing everything on the same thread.
Try to separate the UI from the main thread.
Here is a reading on this topic:
math.hws.edu/javanotes/c12/s2.html
Here, the developer also had a problem with the progressBar.
https://stackoverflow.com/questions/13784333/platf...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question