JavaFX选项卡将进度指示器设置为标题
我在 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();
}
}