Created
September 14, 2021 22:27
-
-
Save NaashNix/089dae20ae67e3cd82c2550a50dbfef3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.scene.control.Alert; | |
import javafx.scene.control.DialogPane; | |
import java.util.Objects; | |
public class ModifiedAlertBox { | |
public Alert alert; | |
public ModifiedAlertBox(String title, Alert.AlertType alertType, String header, | |
String context){ | |
alert = new Alert(alertType); | |
alert.setTitle(title); | |
alert.setHeaderText(header); | |
alert.setContentText(context); | |
// * Accessing dialogPane of the alert box. | |
DialogPane dialogPane = alert.getDialogPane(); | |
// * Styling dialogPane by adding css. | |
try { | |
dialogPane.getStylesheets().add((Objects.requireNonNull(getClass() | |
.getResource("AlertBoxStyle.css"))).toExternalForm()); | |
// * Setting style class | |
dialogPane.getStyleClass().add("myDialog"); | |
}catch (NullPointerException e){ | |
e.printStackTrace(); | |
} | |
} | |
/* | |
--> default .show() method will run when calling this | |
from the object's reference name. | |
*/ | |
public void showAlert(){ | |
this.alert.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment