自定义jfoenix滑块指示器(Customize jfoenix slider indicator)
对于jfoenix滑块,指示器始终随滑块一起更改并相应地显示值。 我们如何在指示中自定义值,例如当从0-4滑动值时我们要在指示上显示“小”。
For the jfoenix slider, the indicator always changed with the slider and show the value accordingly. How can we customize the value in indicate, for example when slide the value from 0-4 we want to show "Small" on the indicate.
最满意答案
我已经自己挖出了答案,只是在这里发布,以防其他人需要欣赏它,如果你能让我知道一些更好的答案。 这是用于将指标中的值格式化为一个小数点,当然您可以添加一些逻辑以基于该值显示一些字符串。
yourSlider.setValueFactory(new Callback<JFXSlider, StringBinding>() { @Override public StringBinding call(JFXSlider arg0) { return Bindings.createStringBinding(new java.util.concurrent.Callable<String>(){ @Override public String call() throws Exception { DecimalFormat df = new DecimalFormat("#.0"); return df.format(yourSlider.getValue()); } }, yourSlider.valueProperty()); } });I've digged out the answer by myself, just post it here in case someone else need that appreciate it if you can let me know some better ones. This one is for formatting the value in the indicator to one decimal point and of course you can add some logic to show some string based on the value.
yourSlider.setValueFactory(new Callback<JFXSlider, StringBinding>() { @Override public StringBinding call(JFXSlider arg0) { return Bindings.createStringBinding(new java.util.concurrent.Callable<String>(){ @Override public String call() throws Exception { DecimalFormat df = new DecimalFormat("#.0"); return df.format(yourSlider.getValue()); } }, yourSlider.valueProperty()); } });更多推荐
发布评论