[英]How to set a jspinner max value from a variable?
I have a few jspinners
, they are: min char
, max cha
r, min low char
, min up chars
etc. Now I need to set the max values of min low char
, min up char
, etc, to the max chars
, but jspinner
models dont allow any variables to set any model value. 我有几个
jspinners
,它们是: min char
, max cha
r, min low char
, min up chars
等。现在我需要将min low char
, min up char
等的max chars
设置为max chars
,但是jspinner
模型不允许任何变量设置任何模型值。 so how can what can I do to set the max values of those spinners to the value of max char
. 那么如何才能将这些微调器的最大值设置为
max char
的值。
The SpinnerNumberModel has setMaximum and setMinimum methods. SpinnerNumberModel具有setMaximum和setMinimum方法。 You could ask the spinner for it's model, and if it's an instanceof SpinnerNumberModel cast it.
您可以向微调器询问它的模型,如果它是SpinnerNumberModel的实例,则将其强制转换。
Otherwise, you could maintain a reference to the original models used to populate the spinners in the first place and update them accordingly. 否则,您可以保留对用于首先填充微调器的原始模型的引用,并相应地更新它们。
You can override getMaximum
with an anonymous model class to make it reference a member of the parent type. 您可以使用匿名模型类覆盖
getMaximum
,以使其引用父类型的成员。 Eg 例如
JSpinner minChar = new JSpinner(new SpinnerNumberModel() {
@Override
public Comparable<Integer> getMaximum() {
return maximum;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.