带有最小和最大按钮的 JSpinner
我正在寻找一个类似 JSpinner 的组件,它提供内置按钮,可以立即将微调器值设置为 jspinner 模型的最小值或最大值。在我自己实现这个之前,我认为以前可能有人做过,尽管我在该主题上的谷歌搜索没有成功。
有这样的组件吗,还是我应该自己编码?感谢您的帮助。
I'm looking for a JSpinner-like component that would provide built-in buttons that would immediately set the spinner value to the minimum or the maximum of the jspinner model. Before implementing this myself, I thought that somebody might have done it before, though my google searches on the topic were not successful.
Is there such a component out there, or should I code it myself ? Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想不出有任何组件可以开箱即用。但基本上,一个带有减号按钮、微调器和最大按钮的简单流程布局就可以了。这两个按钮都有
actionListeners
,它将向微调器询问最小值和最大值并设置其值。在微调器上使用changeListener,以编程方式(使用按钮)和通过用户交互来通知值更改。
此外,如果您的值是离散的,您可以考虑使用 JCombobox,如果不是,则可以考虑使用 JSlider,因为这两个组件都可以更清楚地向用户呈现上限和下限。
问候,
史蒂芬
I can't think of any component that would do it out of the box. But basically, a simple flow layout with a minus button, a spinner and a max button would do. Both buttons would have
actionListeners
that will ask the spinner for min and max values and set its value.Use a changeListener on the spinner to be notified of value changes both programatically (using your buttons) and through user interaction.
Also, you could consider using a JCombobox if your values are discrete or a JSlider if they are not, as both components present upper and lower bounds more clearly to users.
Regards,
Stéphane
我认为自己实现它会很简单
1)我将创建一个扩展 JPanel 的类。
2) 在此类中,您必须定义滑块和按钮的放置位置以及与按钮相关的操作。
3) 您可以将您已实现的类的 JPanel 实例添加到您的应用程序中。
I think it would be simple to implemt it by yourself
1) I would create a class that extend JPanel.
2) In this class you have to define where your slider and buttons have to be placed and the actions correlated to the button.
3) You can add to your application JPanel instances of the class the you have implemented.
您必须阅读 如何使用 Spinners ,然后您可以能够为 SpinnerNumberModel
例如(作者:StanislavL)
you have to read How to Use Spinners , and then you can be able set these value exactly for SpinnerNumberModel
for example (by StanislavL)