6

As the title says, I need to make a thin progress bar. I used this:

progressBar.setMaxHeight(0.1);
progressBar.setPrefHeight(0.1);

but that doesn't work. Does anyone have an idea?

Nick Rippe
  • 6,465
  • 14
  • 30
szeljic
  • 183
  • 8

1 Answers1

7

You'll have to mess around with the styling to get it any smaller. I really recommend taking a look a the caspian.css that's included with Javafx - that's the default style sheet. It helps a lot when trying to override the look and feel of the default skins. Here's an example I put together that shows how it can be done:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class ProgressBarTest extends Application {

    public static void main(String[] args) { launch(args); }

    @Override
    public void start(final Stage stage) throws Exception {
        //All the controls are added here
        VBox box = new VBox();
        box.getStylesheets().add("test.css");
        ProgressBar pb = new ProgressBar(50);

        box.getChildren().add(pb);

        //Setting up your scene
        Scene scene = new Scene(box);
        stage.setScene(scene);

        stage.show();
    }
}

And here's the test.css I loaded up:

.progress-bar .bar {-fx-padding:1px; -fx-background-insets:0;}

And here is the output of the test app:

small progress

Nick Rippe
  • 6,465
  • 14
  • 30
  • 4
    I added the answer to this question to the [StackOverflow JavaFX Progress Bar Styling Community Wiki Answer](http://stackoverflow.com/questions/19417246/how-can-i-style-the-progressbar-component-in-javafx). – jewelsea Feb 12 '14 at 23:45