带有最小和最大按钮的 JSpinner [英] A JSpinner with min and max buttons

查看:19
本文介绍了带有最小和最大按钮的 JSpinner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个类似于 JSpinner 的组件,它提供内置按钮,可以立即将微调器值设置为 jspinner 模型的最小值或最大值.在自己实施之前,我认为之前可能有人做过,尽管我对该主题的 google 搜索没有成功.

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.

推荐答案

我想不出任何开箱即用的组件.但基本上,一个带有减号按钮、一个微调器和一个最大按钮的简单流布局就可以了.两个按钮都有 actionListeners ,它会向微调器询问最小值和最大值并设置其值.

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.

在微调器上使用 changeListener 以通过编程(使用您的按钮)和通过用户交互来通知值更改.

Use a changeListener on the spinner to be notified of value changes both programatically (using your buttons) and through user interaction.

此外,如果您的值是离散的,您可以考虑使用 JCombobox,否则您可以考虑使用 JSlider,因为这两个组件都向用户更清楚地显示了上限和下限.

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.

问候,斯蒂芬

这篇关于带有最小和最大按钮的 JSpinner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆