JavaFX Tab 将进度指示器设置为标题
JavaFX Tab set a progreess indicator as title
我在 JavaFX 中使用 TabPane 并在任务 运行 时创建它们。任务完成后,我将标签交换为包含任务结果的新标签。
我想在选项卡的标题中显示加载微调器(javaFX 术语:进度指示器)。
这可能吗?
像这样:
是的,只需使用 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);
}
完整的可运行示例:
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();
}
}
我在 JavaFX 中使用 TabPane 并在任务 运行 时创建它们。任务完成后,我将标签交换为包含任务结果的新标签。
我想在选项卡的标题中显示加载微调器(javaFX 术语:进度指示器)。
这可能吗?
像这样:
是的,只需使用 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);
}
完整的可运行示例:
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();
}
}