List of usage examples for javax.swing JFormattedTextField getCaretPosition
@Transient public int getCaretPosition()
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 . j ava2s . 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); }