Question

I am in need of a JSpinner that can handle long, but JSpinner only handles double and int. I did see an answer that used double to simulate a long, but I need to be able to exactly represent each value of long. It is a program that works with each of the 64 bits, so double and int will not do.

Is it possible to have a JSpinner use BigInteger as the data type, or would I be better off just making designing my own JSpinner using a JPanel holding a JTextField and two JButtons specifically to handle my situation? Right now, I'm leaning towards the latter.

Was it helpful?

Solution

As @Aru mentioned, you can do it with the SpinnerNumberModel:

Long val = Long.MAX_VALUE;//set your own value, I used to check if it works
Long min = Long.MIN_VALUE;
Long max = Long.MAX_VALUE;
Long step = 1L;

SpinnerNumberModel model = new SpinnerNumberModel(val, min, max, step);
JSpinner spinner = new JSpinner(model);

Note that you have to use Long as an object not a primitive long

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top