How to set specific css value for javaFX ProgressBar during Runtime? -


i have usual css progressbar:

.progress-bar > .track {   -fx-background-color: transparent; } .progress-bar > .bar {   -fx-background-color: transparent;   -fx-background-image: url('/images/progress_bar.png');   -fx-background-size: 1600px 50px;   -fx-background-repeat: no-repeat; } 

image progress_bar.png 3-colored bar changes green red reaches it's end. works nicely when application run.

my problem hard coded values background size. work on full hd displays on 1366x768 of yellow/red parts cut out. set property during run-time match screen size. possible?

i tried use setstyle() method in progressbar without success. maybe doing wrong if has working example...

i tried set width 100% (instead of px) not work either. shows compressed bar , stretches 100% width.

here image: progress_bar.png

i don't think possible using css alone. customized skin used replaces bar node imageview , uses bar clip instead:

progress.barbackgroundprogressbarskin

public class barbackgroundprogressbarskin extends progressbarskin {      public barbackgroundprogressbarskin(progressbar control) {         super(control);     }      private imageview barbackground;      @override     protected void initialize() {         super.initialize();          barbackground = new imageview();          barbackground.setmanaged(false);          barbackground.setpreserveratio(false);         barbackground.getstyleclass().setall("bar-background");         int barindex;          list<node> children = getchildren();         int size = children.size();          (barindex = 0; barindex < size && !children.get(barindex).getstyleclass().contains("bar"); barindex++) {         }          region bar = (region) children.set(barindex, barbackground);         barbackground.setclip(bar);          // fill bar clipping         bar.setbackground(new background(new backgroundfill(color.white, new cornerradii(2), new insets(3, 3, 4, 3))));     }      @override     protected void layoutchildren(double x, double y, double w, double h) {         // set pos         barbackground.setlayoutx(x);         barbackground.setlayouty(y);          // set size         barbackground.setfitheight(h);         barbackground.setfitwidth(w);          super.layoutchildren(x, y, w, h);     }  } 

style.css

.progress-bar {     -fx-skin: 'progress.barbackgroundprogressbarskin'; }  .progress-bar > .bar-background {     /* image goes here */     -fx-image: url('http://i.stack.imgur.com/gluad.png'); }  .progress-bar > .track {     -fx-background-color: transparent; } 

demo

@override public void start(stage primarystage) {      progressbar progressbar = new progressbar();      stackpane root = new stackpane();     root.getchildren().add(progressbar);     progressbar.setprefsize(300, 18);      scene scene = new scene(root, 200, 200);      scene.getstylesheets().add(getclass().getresource("style.css").toexternalform());      timeline tl = new timeline(             new keyframe(duration.zero, new keyvalue(progressbar.progressproperty(), 0d)),             new keyframe(duration.seconds(10), new keyvalue(progressbar.progressproperty(), 1d, interpolator.ease_out))     );      tl.setcyclecount(animation.indefinite);     tl.play();      primarystage.setscene(scene);     primarystage.show(); } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -