user interface - Text area for progress bar -
i add text area user can see information can see in console while progress bar updating.
how can add text area ?
here sample of code have used make progress bar. can add below progress bar text area should fill while computations mare?
import javafx.application.application; import javafx.concurrent.task; 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.label; import javafx.scene.control.progressbar; import javafx.scene.control.progressindicator; import javafx.scene.layout.hbox; import javafx.scene.layout.stackpane; import javafx.stage.modality; import javafx.stage.stage; import javafx.stage.stagestyle; public class progressdialogexample extends application { static int option = 0; static progressform pform = new progressform(); @override public void start(stage primarystage) { button startbutton = new button("start"); startbutton.setonaction(e -> { // in real life task useful , return // meaningful result: task<void> task = new task<void>() { @override public void call() throws interruptedexception { (int = 0; < 10; i++) { updateprogress(i, 10); thread.sleep(200); } updateprogress(10, 10); return null; } }; // binds progress of progress bars progress of task: pform.activateprogressbar(task); // in real life method result of task // , update ui based on value: task.setonsucceeded(event -> { startbutton.setdisable(false); }); startbutton.setdisable(true); pform.getdialogstage().show(); thread thread = new thread(task); thread.start(); }); stackpane root = new stackpane(startbutton); scene scene = new scene(root, 350, 75); primarystage.setscene(scene); primarystage.show(); } private int closewindow() { return option; } private static void setclosewindow() { // todo auto-generated method stub option = 1; } public static class progressform { private final stage dialogstage; private final progressbar pb = new progressbar(); private final progressindicator pin = new progressindicator(); public progressform() { dialogstage = new stage(); dialogstage.initstyle(stagestyle.utility); // dialogstage.setresizable(false); // dialogstage.setwidth(400); // dialogstage.setheight(300); // final vbox vbox = new vbox(); dialogstage.initmodality(modality.application_modal); final button exitbutton = new button("exit"); exitbutton.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent e) { pform.getdialogstage().close(); setclosewindow(); } }); // progress bar pb.setprogress(-1f); pin.setprogress(-1f); final hbox hb = new hbox(); hb.setspacing(5); hb.setalignment(pos.center); hb.getchildren().addall(pb, pin, exitbutton); scene scene = new scene(hb); dialogstage.setscene(scene); } public void activateprogressbar(final task<?> task) { pb.progressproperty().bind(task.progressproperty()); pin.progressproperty().bind(task.progressproperty()); dialogstage.show(); } public stage getdialogstage() { return dialogstage; } } public static void main(string[] args) { launch(args); } }
have heard of label
labelled
before use label
instead of text node
want use , write text when want to, when want show progressbars
label.setgraphic(myprogressbarnode);
hope helps
edit
i add text area user can see information can see in console while progress bar updating... can add below progress bar text area should fill while computations mare?
and gave solution it.
suppose have progressbar
pb
; , adding progressbar stackpane
not have add progressbar
directly rather add text
implement label
presume label
lb
how code like
stackpane sp; // parent progressbar pb; // progress indicator lable lb; // text area sp.getchildren().add(lb);// have added text area lb.setgraphic(pb); have added progressbar text area lb.setcontentdisplay(contentdisplay.***);//the *** represents position want graphic //whether top or left or bottom //now done, pb show aligned lb, , updated //if want show text lb.settext("your text");
how implicit this? :-)
Comments
Post a Comment