Displaying single pane alert in javafx

Viewed 42

I am using the following code to show an error alert :

 Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setContentText(resourceBundle.getString("loginError"));
            alert.showAndWait();

enter image description here

This alert looks a little weird to me as there are two panes the top one just showing Error and a cross button and the bottom one showing the text incorrect username or password
Is there some way to get rid of the top pane? As the header pane already showing Error and cross button I don't see the reason for the next pane to show Error and a red cross button

2 Answers

To remove the header try,

alert.setHeaderText(null);

To remove the icon try,

alert.setGraphic(null);
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setContentText("Incorrect Username or Password");
alert.setHeaderText(null);
alert.setGraphic(null);
alert.showAndWait();

enter image description here

Alert alert = new Alert(Alert.AlertType.NONE);

This will remove the header alert.

Related