sabbibJAVA
sabbibJAVA

Reputation: 1076

How to set a jspinner max value from a variable?

I have a few jspinners, they are: min char, max char, 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. so how can what can I do to set the max values of those spinners to the value of max char.

Upvotes: 1

Views: 5695

Answers (2)

Jacob is on Codidact
Jacob is on Codidact

Reputation: 3750

You can override getMaximum with an anonymous model class to make it reference a member of the parent type. E.g.

JSpinner minChar = new JSpinner(new SpinnerNumberModel() {
  @Override
  public Comparable<Integer> getMaximum() {
    return maximum;
  }
});

Upvotes: 1

MadProgrammer
MadProgrammer

Reputation: 347234

The SpinnerNumberModel has setMaximum and setMinimum methods. You could ask the spinner for it's model, and if it's an instanceof SpinnerNumberModel cast it.

Otherwise, you could maintain a reference to the original models used to populate the spinners in the first place and update them accordingly.

Upvotes: 3

Related Questions