B4J Question Change color of progress bar, how?

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I would like to change the color of the bar in the progress bar control in B4J.

I found the following in a thread, but it does not seem to address the bar color.
B4X:
progressbar.style="-fx-box-border: black; -fx-accent: red;"

In the designer you can click on the Style drop-down, but I don't see anything that relates to the actual bar color.

upload_2015-4-30_12-43-15.png


Is there a way to set the color for the bar in the progress bar?

More importantly, can someone point me to where I can find the documentation for the style settings and their effects on the various controls? I have attempted Googling this, but so far no success.

Thanks,
Barry.
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

look up here.

You can define own styleclasses, like below. One way to use:
  • Store these classes in files folder as f.e. main.css.
  • Open JavaFX SceneBuilder, add stylesheet main.css to the main achorpane, select the progressbar and assign a style class, like red-progress-bar.
  • Then re-run the B4J app
B4X:
.my-progress-bar .bar {
        -fx-background-radius: 5;
}
.my-progress-bar .track {
    -fx-background-radius: 5;
}
.my-progress-bar {
    -fx-background-radius: 5;   
}
.red-progress-bar .bar {
        -fx-background-color: red;
}
.blue-progress-bar .bar {
        -fx-background-color: blue;
}
.green-progress-bar .bar {
        -fx-background-color: green;
}
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,

Thanks for your response and thanks for the documentation link:
http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#progressbar

I tried -fx-progress-color

B4X:
progressbar.style="-fx-progress-color: green;"

As the documentation seems to indicate. However, it did not change the progress bar color.

I also tried several of the other "-fx" options available in the designer. Nothing seem to make much of a difference.

I would rather use an in-line style rather than styleclasses so that the jar file remains self-contained.

Does this only work with styleclasses? Should my command have been different?

Thanks,
Barry.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Then you can use a for example a JavaObject. Example:

B4X:
'Set the color of progressbar
'Parameter: ProgressBar, Color as string
'Examples:
'Private pbMain as ProgressBar
'setProgressBarColor(pbMain, "red")
'setProgressBarColor(pbMain, "green")
Sub setProgressBarColor(pb As ProgressBar, color As String)
    Dim joPB As JavaObject = pb
    joPB.RunMethodJo("lookup", Array(".bar")).RunMethod("setStyle", Array("-fx-background-color: " & color & ";"))
    'Call without parameter: joPB.RunMethodJo("lookup", Array(".bar")).RunMethod("setStyle", Array("-fx-background-color: red;"))
End Sub
 
Upvote 0
Top