我已經實現了Jspinner,其中我添加了mouseClicked Listener,它將微調器設置爲當前日期時間,但是在成功提交相同微調器需要設置爲空白後工作正常,但當我點擊第二次微調,它顯示舊值以及mouseClicked Listener沒有被調用爲什麼? 注意:我爲Spinner使用SpinnerDateModel。將更新後的值設置爲JSpinner
private void spinnerMouseClicked(java.awt.event.MouseEvent evt) {
spinner.setModel(new SpinnerDateModel(new Date(), null, null, Calendar.HOUR_OF_DAY));
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm");
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setFormatterFactory(new DefaultFormatterFactory(new DateFormatter(format)));
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if (0 == ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getCaretPosition()) {
if (((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getText().length() > 13) {
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setCaretPosition(13);
}
}
}
});
}
private void submit(){
((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setText(null);
}
很難說沒有看到您的代碼:) – dic19
沒有人知道,投票結束 – mKorbel