How to set JSpinner as non editable?

佐手、 提交于 2019-11-28 01:48:15

Try the following:

JSpinner spinner = ...;
((DefaultEditor) spinner.getEditor()).getTextField().setEditable(false);

This should work as long as you didn't change the spinner editor yourself by calling spinner.setEditor(...).

Tell us if this helps.

A bit shorter:

JSpinner spinner = new JSpinner();
spinner.setEditor(new JSpinner.DefaultEditor(spinner));

When I try this, the spinner can still be edited by click the arrow! – yelliver

You can try setting the step to 0:

mySpinner.setModel(new SpinnerNumberModel(yourDefaultDisplayValue, minValue, maxValue, step));

You can explore the other spinner models and do the same trick I guess.

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