自定义jfoenix滑块指示器(Customize jfoenix slider indicator)

编程入门 行业动态 更新时间:2024-10-27 04:37:42
自定义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()); } });

更多推荐

本文发布于:2023-08-05 20:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指示器   自定义   滑块   jfoenix   indicator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!