我需要一个可以处理 long 的 JSpinner,但 JSpinner 只能处理 double 和 int。我确实看到了一个使用 double 来模拟 long 的答案,但我需要能够准确表示 long 的每个值。它是一个适用于每个 64 位的程序,因此 double 和 int 不行。
是否可以让 JSpinner 使用 BigInteger 作为数据类型,或者我最好使用包含 JTextField 和两个 JButton 的 JPanel 来设计自己的 JSpinner 来专门处理我的情况?目前,我倾向于后者。
最佳答案
正如 @Aru 提到的,您可以使用 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
关于java - 具有长值的 JSpinner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23252736/