JSlider 双打
我正在为扑克框架制作一个 GUI(使用 swing),并且需要某种滑块来允许玩家选择下注大小。然而,Swing JSlider 仅适用于 int 值,而我需要一些可以支持 1 个小数点的双精度值的东西。有没有我可以使用的库,或者 JSlider
的技巧?
I am making a GUI (using swing) for a poker framework and need some sort of slider to allow players to select a bet size. However the Swing JSlider
only works with int values whereas I need something that can support doubles for 1 decimal point. Are there any libraries I can use, or tricks with the JSlider
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将该值乘以 10
编辑
您可以更改显示的标签,如下所示:
You can multiply the value by 10
EDIT
You can change the labels displayed as follows:
您可以在 JSlider 中使用的一个技巧是使用美分作为单位。因此,如果您希望用户选择 1 到 10 美元之间的金额,您实际上将 JSlider 设置为 100 到 1000 的范围。然后,当用户选择一个值时,您只需将该值转换为美元和美分即可。
然后,您可以使用值字典来指定滑块上的任何值显示的标签。为此,请使用
setLabelTable()
方法。One trick you can use with JSlider is to use the units in cents. So if you want the user to select an amount between 1 and 10 dollars you actually set the JSlider to the range 100 to 1000. Then you simply convert the value to dollars and cents when the user selects a value.
You can then use a Dictionary of values to specify what label is displayed at any value on the slider. Use the
setLabelTable()
method for this.