简体   繁体   English

是否可以禁用 JSpinner 向下箭头按钮? 怎么样?

[英]Is it possible to disable a JSpinner down arrow button? How?

I have a JSpinner which starts at 0 and when its value is 0, its down arrow button should be disabled so the value does not change.我有一个 JSpinner,它从 0 开始,当它的值为 0 时,它的向下箭头按钮应该被禁用,因此该值不会改变。 Does anyone knows how to disable a button in a JSpinner?有谁知道如何禁用 JSpinner 中的按钮?

You can use a SpinnerModel.您可以使用 SpinnerModel。 Eg the following line limits the values between 0 and MAX_VALUE (ie values are bounded by zero from below).例如,以下行将值限制在 0 和 MAX_VALUE 之间(即值从下方以零为界)。 Arguments are: value, min, max, step_size.参数是:值、最小值、最大值、步长。

JSpinner jSpinner = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));

Note: the button is not disabled actually, but does not decrease the value.注意:该按钮实际上并未禁用,但不会减小该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM