How to show ProgressIndicator in center of Pane in Javafx -


i have pane controls , button. when click on button, want show progressindicator in center of pane without removing controls.

when adding progressindicator pane during onaction of button, adds below button. want overlay on pane.

the picture below explains want.

progress indicator

code

package fx;  import javafx.application.application; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.progressindicator; import javafx.scene.control.textfield; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class main extends application {  @override public void start(stage arg0) throws exception {     final vbox bx = new vbox();     bx.setalignment(pos.center);     textfield username = new textfield("user name");     username.setmaxwidth(200);     textfield email = new textfield("email");     email.setmaxwidth(200);     button submit = new button("submit");     submit.setonaction(new eventhandler<actionevent>() {          public void handle(actionevent event) {             progressindicator pi = new progressindicator();             //adding here adding @ below of button             //how here             bx.getchildren().add(pi);             //further process           }     });     bx.getchildren().addall(username, email, submit);     scene c = new scene(bx);     arg0.setscene(c);     arg0.setminwidth(500);     arg0.setminheight(500);     arg0.show();   }    public static void main(string[] args) {      main h = new main();      h.launch(args);   } } 

you need use stackpane root layout instead of using vbox. stackpane allows stack nodes on top of each other (z-order).

on button's action can create new progressindicator , add stackpane. have introduced vbox parent indicator, because did not want indicator capture available space. can disable present vbox greying effect on button's action after process done can enable vbox again.

enter image description here


import javafx.application.application; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.progressindicator; import javafx.scene.control.textfield; import javafx.scene.layout.stackpane; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class main extends application {      @override     public void start(stage arg0) throws exception {         stackpane root = new stackpane();         vbox bx = new vbox();         bx.setalignment(pos.center);         textfield username = new textfield("user name");         username.setmaxwidth(200);         textfield email = new textfield("email");         email.setmaxwidth(200);         button submit = new button("submit");         submit.setonaction(new eventhandler<actionevent>() {              public void handle(actionevent event) {                 progressindicator pi = new progressindicator();                 vbox box = new vbox(pi);                 box.setalignment(pos.center);                 // grey background                 bx.setdisable(true);                 root.getchildren().add(box);             }         });         bx.getchildren().addall(username, email, submit);         root.getchildren().add(bx);         scene c = new scene(root);         arg0.setscene(c);         arg0.setminwidth(500);         arg0.setminheight(500);         arg0.show();     }      public static void main(string[] args) {         launch(args);     } } 

Comments