1 year ago

#322301

test-img

okmred

JAVAFX custom icons on dialogs not working

All, I have inherited some code that I am just cleaning up and doing some tweaks to. The 1st thing I want to do is add the custom icon to all the popups in the application. However, I am running into some roadblocks. Here is the current piece of code I am working with:

    onDeleteClick(ActionEvent event) {
    // delete 
    System.out.println("Deleting");

    Alert alert = new Alert(AlertType.CONFIRMATION, "do you want to delete?", ButtonType.YES,
            ButtonType.NO);
    alert.setTitle("Delete ");
    alert.setHeaderText("You are about to delete " + code.getText());
    alert.initOwner(((Button)event.getSource()).getScene().getWindow()); //recently added displays correct icon
    alert.showAndWait();

    if (alert.getResult() == ButtonType.YES) {
    ProgressIndicator pi = new ProgressIndicator(); //progress indicator does not display correctly
    VBox box = new VBox(pi);
    box.setAlignment(Pos.CENTER);
    final Stage Dialog = new Stage();
    Dialog.initModality(Modality.APPLICATION_MODAL);
    Dialog.setTitle("Deleting, Please Wait!");
            
    // Get the Stage.  I found this code but it does not display the custom icon.
    //Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
    // Add a custom icon.
    //Dialog.getIcons().add(new Image(this.getClass().getResource("my.ico").toString()));
    
    Dialog.centerOnScreen();
    Dialog.setHeight(200);
    Dialog.setWidth(300);
    Dialog.setResizable(false);
        
    TilePane tp = new TilePane();
    Label label = new Label();
    label.setText("Please wait for deletion to complete."); // added due to progress indicator failure

    tp.getChildren().add(label);
    tp.getChildren().add(pi);
    Scene 1Scene = new Scene(tp);
            
    Dialog.setScene(1Scene);
    Dialog.show(); 

Thanks for any help/direction with displaying the custom icon in the dialog.

javafx

javafx-8

0 Answers

Your Answer

Accepted video resources