具有长值的JSpinner [英] JSpinner with long values

查看:90
本文介绍了具有长值的JSpinner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个可以处理很长时间的JSpinner,但是JSpinner只处理double和int.我确实看到了一个使用double来模拟long的答案,但是我需要能够准确表示long的每个值.该程序可使用64位中的每一个,因此double和int将不起作用.

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.

是否有可能让JSpinner使用BigInteger作为数据类型,还是只使用包含一个JTextField和两个JButton的JPanel专门设计自己的JSpinner来更好地处理我的情况呢?现在,我倾向于后者.

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.

推荐答案

如@Aru所述,您可以使用SpinnerNumberModel:

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);

请注意,您必须将Long用作对象,而不是原始的long

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

这篇关于具有长值的JSpinner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆