List of usage examples for javax.swing JFormattedTextField setCaretPosition
@BeanProperty(bound = false, description = "the caret position") public void setCaretPosition(int position)
TextComponent
. From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java
@Override public void setEditor(final JFormattedTextField editor) { final int ENTER_CODE = 10; editor.addKeyListener(new KeyAdapter() { @Override/* ww w . jav a 2s .co m*/ public void keyTyped(KeyEvent e) { if (e.getKeyChar() == '\u007F' && editor.getCaretPosition() < format.length()) { editor.setCaretPosition(editor.getCaretPosition() + 1); } } @Override public void keyPressed(KeyEvent event) { if (ENTER_CODE == event.getKeyCode()) try { editor.commitEdit(); } catch (ParseException e) { // } } }); editor.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { editor.setCaretPosition(0); } }); super.setEditor(editor); if (format == null) { setFormats( Datatypes.getFormatStrings(AppBeans.get(UserSessionSource.class).getLocale()).getDateFormat()); } else setFormats(format); }