1

I want a listener that autoselects the entry on the JXDatePickers editor cell when same gains focus.

DatePicker.getEditor().selectAll();

doesn´t work. So i tried this :

DatePicker.getEditor().addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {

                    DatePicker. getEditor().selectAll();
                }
             });
        }

public void focusLost(FocusEvent e) {
}
});

Any suggestions ?

Jannis Alexakis
  • 1,279
  • 4
  • 19
  • 38

1 Answers1

1

Edit

just realized that you probably have stand-alone datepicker, and run your snippet: worksforme. So we'll need to dig for differences - what's your swingx/jdk version and OS?

Original

typically, the JFormattedTextField is tricky to convince being selected ;-) See

Combining JXTable with RXTable

and adapt the solution to handle JXDatePicker as well - by adding

    if (editor instanceof JXDatePicker) {
        LOG.info("got picker: " + editor);
        invokeSelectAll(((JXDatePicker) editor).getEditor());
        return;
    }
Community
  • 1
  • 1
kleopatra
  • 51,061
  • 28
  • 99
  • 211