/**
* 设置JSpinner的编辑属性
* @param spinner 目标JSpinner
* @param isAllowInvalid 是否允许输入非法值
* @param isEditable 是否允许编辑
*/
public static void setAllowsInvalid(JSpinner spinner, boolean isAllowInvalid, boolean isEditable)
{
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "#");
spinner.setEditor(editor);
JFormattedTextField tf = ((JSpinner.NumberEditor)spinner.getEditor()).getTextField();
tf.setEditable(isEditable);
DefaultFormatterFactory factory = (DefaultFormatterFactory)tf.getFormatterFactory();
NumberFormatter formatter = (NumberFormatter)factory.getDefaultFormatter();
formatter.setAllowsInvalid(isAllowInvalid);
}
设置JSpinner的编辑属性
最新推荐文章于 2021-02-26 05:46:21 发布