Jannis Alexakis
Jannis Alexakis

Reputation: 1319

JXDatePicker and selectAll()

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 ?

Upvotes: 1

Views: 385

Answers (1)

kleopatra
kleopatra

Reputation: 51536

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;
    }

Upvotes: 1

Related Questions