Community
Participate
Working Groups
Running the the snippet below on Windows or with Carbon, one can use the keyboard arrows to navigate inside the DateTime widget. Also, the Page Up and Page Down keys change the month backwards and forwards. However, these events are not triggered on Cocoa. import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class Snippet250 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final DateTime calendar = new DateTime(shell, SWT.CALENDAR); calendar.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (calendar.getMonth () + 1) + "/" + calendar.getDay () + "/" + calendar.getYear ()); } }); calendar.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { System.out.println("calendar date changed"); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Unfortunately this is platform behavior. NSDatePicker doesn't support keyboard-based navigation. But, once bug 277638 is fixed you can make a DateTime with SWT.DATE and SWT.DROP_DOWN set and then use the keyboard to adjust the date elements. The calendar drop-down will update to match the textual date.