Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Tab set a progreess indicator as title

Tags:

javafx

I am using a TabPane in JavaFX and create them when a task is running. When the task has finished, I exchange the tab with a new tab which contains the result of the task.

I would like to show a loading spinner (javaFX terms: progress indicator) in the title of the tab.

Is that possible?

Like this:

enter image description here

like image 928
MoritzMeinhardt Avatar asked Apr 16 '21 13:04

MoritzMeinhardt


1 Answers

Yes it is possible just use the tab.setGraphic(...);

/**
 * <p>Sets the graphic to show in the tab to allow the user to differentiate
 * between the function of each tab. By default the graphic does not rotate
 * based on the TabPane.tabPosition value, but it can be set to rotate by
 * setting TabPane.rotateGraphic to true.</p>
 */
public final void setGraphic(Node value) {
    graphicProperty().set(value);
}

Full Runnable Example:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        ProgressIndicator progressIndicator = new ProgressIndicator();

        Tab tab = new Tab();
        tab.setClosable(false);
        tab.setGraphic(progressIndicator);

        TabPane tabPane = new TabPane(tab);
        tabPane.setPrefSize(200,200);

        primaryStage.setScene(new Scene(tabPane));
        primaryStage.show();
    }
}
like image 108
Matt Avatar answered Oct 08 '22 20:10

Matt