JSlider 双打

发布于 2024-08-20 11:02:04 字数 147 浏览 9 评论 0原文

我正在为扑克框架制作一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-08-27 11:02:04

您可以将该值乘以 10

编辑

您可以更改显示的标签,如下所示:

Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("0.0") );
labelTable.put( new Integer( 5 ), new JLabel("0.5") );
labelTable.put( new Integer( 10 ), new JLabel("1.0") );
framesPerSecond.setLabelTable( labelTable );

You can multiply the value by 10

EDIT

You can change the labels displayed as follows:

Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("0.0") );
labelTable.put( new Integer( 5 ), new JLabel("0.5") );
labelTable.put( new Integer( 10 ), new JLabel("1.0") );
framesPerSecond.setLabelTable( labelTable );
人│生佛魔见 2024-08-27 11:02:04

您可以在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文