how can I change default text "Done" under ProgressIndicator in JavaFX?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is a little bit tricky but it is possible:
In JavaFX 2.2 this is made like this:
ProgressIndicator indicator = new ProgressIndicator();
ProgressIndicatorSkin indicatorSkin = new ProgressIndicatorSkin(indicator);
final Text text = (Text) indicatorSkin.lookup(".percentage");
indicator.progressProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number newValue) {
// If progress is 100% then show Text
if (newValue.doubleValue() >= 1) {
// This text replaces "Done"
text.setText("Foo");
}
}
});
indicator.skinProperty().set(indicatorSkin);
indicator.setProgress(1);
In JavaFX 8 you must first call applyCss()
before doing a lookup and you do not need the skin anymore:
ProgressIndicator indicator = new ProgressIndicator();
indicator.progressProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number newValue) {
// If progress is 100% then show Text
if (newValue.doubleValue() >= 1) {
// Apply CSS so you can lookup the text
indicator.applyCss();
Text text = (Text) indicator.lookup(".text.percentage");
// This text replaces "Done"
text.setText("Foo");
}
}
});
indicator.setProgress(1);
Change the text "Foo" to your finished Text and you are ready
I have tested this code and it should work fine. ;-)