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 ?
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;
}
精彩评论