If the spinner uses JSpinner.DefaultEditor or its subclass, the following code works (the keyboard is disabled, the counter buttons do not work, but you can select and copy the value displayed on the counter).
JSpinner component = ...; component.setEnabled( false ); if ( component.getEditor() instanceof JSpinner.DefaultEditor ) { JSpinner.DefaultEditor editor = ( JSpinner.DefaultEditor ) component.getEditor(); editor.getTextField().setEnabled( true ); editor.getTextField().setEditable( false ); }
If the spinner has its own editor with something other than JTextComponent, then you can probably still use the same approach (disable the counter, re-enable the actual component used by the spinner editor, mark this component read as using only the API).
source share