How can I disable the textfield area of JSpinner

空扰寡人 提交于 2020-01-17 12:26:32

问题


I'm currently having a problem in netbeans where my JSpinner is allowing you to type in the textfield while I only want the arrows to be used. Is there a way to disable the input of text via properties or some other way?

Thanks


回答1:


Disable the JSpinner's JTextField's using the following:

((JSpinner.DefaultEditor) yourSpinner.getEditor()).getTextField().setEditable(false);



回答2:


You can try it like this

 JSpinner.DefaultEditor editor = ( JSpinner.DefaultEditor ) component.getEditor();
editor.getTextField().setEnabled( true );
editor.getTextField().setEditable( false );


来源:https://stackoverflow.com/questions/29105382/how-can-i-disable-the-textfield-area-of-jspinner

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