JSpinner with long values

隐身守侯 提交于 2019-12-11 09:34:54

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/23252736/jspinner-with-long-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!