简体   繁体   English

如何从变量设置jspinner最大值?

[英]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 charmax cha r, min low charmin up chars等。现在我需要将min low charmin 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.

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