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:
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With