javafx - Set image on left side of dialog -


i created simple example javafx alert dialog javafx8u40.

public class mainapp extends application {     public static void main(string[] args)     {         application.launch(args);     }      private stage stage;      @override     public void start(stage primarystage) throws exception     {         button create = new button("create alert");         create.settooltip(new tooltip("create alert dialog"));         create.setonaction(e ->         {             createalert();         });          primarystage.setscene(new scene(create));         primarystage.show();          stage = primarystage;     }      protected alert createalert()     {         alert alert = new alert(alerttype.warning);         image image1 = new image("http://www.mcaprojecttraining.com/images/java-big-icon.png");          imageview imageview = new imageview(image1);          alert.setgraphic(imageview);         alert.initmodality(modality.application_modal);         alert.initowner(stage);         alert.getdialogpane().setcontenttext("some text");          alert.showandwait()             .filter(response -> response == buttontype.ok)             .ifpresent(response -> system.out.println("the alert approved"));          return alert;     }  } 

i'm interested how can set image on left side of dialog.

did manage change side of image?

enter image description here

if have @ how header constructed, you'll find gridpane node layout label on left , stackpane icon.

if want reverse cells order code, can it, overriden every time updateheaderarea() called.

my suggestion using public api:

dialogpane.setheader(node header); dialogpane.setgraphic(node graphic); 

providing header icon on left , label, , null graphic.

using same approach dialogpane, add gridpane header:

protected alert createalert(){     alert alert = new alert(alerttype.warning);      alert.initmodality(modality.application_modal);     alert.initowner(stage);     alert.getdialogpane().setcontenttext("some text");      dialogpane dialogpane = alert.getdialogpane();     gridpane grid = new gridpane();     columnconstraints graphiccolumn = new columnconstraints();     graphiccolumn.setfillwidth(false);     graphiccolumn.sethgrow(priority.never);     columnconstraints textcolumn = new columnconstraints();     textcolumn.setfillwidth(true);     textcolumn.sethgrow(priority.always);     grid.getcolumnconstraints().setall(graphiccolumn, textcolumn);     grid.setpadding(new insets(5));      image image1 = new image("http://www.mcaprojecttraining.com/images/java-big-icon.png");     imageview imageview = new imageview(image1);     imageview.setfitwidth(64);     imageview.setfitheight(64);     stackpane stackpane = new stackpane(imageview);     stackpane.setalignment(pos.center);     grid.add(stackpane, 0, 0);      label headerlabel = new label("warning");     headerlabel.setwraptext(true);     headerlabel.setalignment(pos.center_right);     headerlabel.setmaxwidth(double.max_value);     headerlabel.setmaxheight(double.max_value);     grid.add(headerlabel, 1, 0);      dialogpane.setheader(grid);     dialogpane.setgraphic(null);      alert.showandwait()         .filter(response -> response == buttontype.ok)         .ifpresent(response -> system.out.println("the alert approved"));      return alert; } 

and see:

alert


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -