【发布时间】:2021-04-16 13:00:42
【问题描述】:
我在 JavaFX 中使用 TabPane 并在任务运行时创建它们。任务完成后,我将选项卡更换为包含任务结果的新选项卡。
我想在标签的标题中显示一个加载微调器(javaFX 术语:进度指示器)。
这可能吗?
像这样:
【问题讨论】:
标签: javafx
我在 JavaFX 中使用 TabPane 并在任务运行时创建它们。任务完成后,我将选项卡更换为包含任务结果的新选项卡。
我想在标签的标题中显示一个加载微调器(javaFX 术语:进度指示器)。
这可能吗?
像这样:
【问题讨论】:
标签: 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();
}
}
【讨论】: