javajcalendarjdatechooser

JCalendar Focus Event


I use JCalendar's JDateChooser in a table date column as a tablecelleditor. The problem is that when the column cell clicked JDateChooser appears but if it loses its focus it does not fire focus lost event. How to make it fire focus lost event? And after doing this is there any way to prevent its firing focus lost when JCalendar appeared after clicking the JCalendar Button?

The thing I try to do is if some one specify a date by selecting a date from the calendar stopCellEditing(); Else wait until focus lost event to stop or cancelCellEditing();

enter image description here


Solution

  • I found a propertyChanged event in JDateChooser which is fired when a date selected. And jTable1.putClientProperty("terminateEditOnFocusLost", true); make the table terminate edit on focusLost

    Edit : When calendar popup is down if you want to change the year that make table cell lose focus and terminateEditing :(

    jDateChooser.addPropertyChangeListener(new PropertyChangeListener() {
    
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("date")) {
                stopCellEditing();
            }
        }
    });
    

    Edit(Solved) : Instead of using jTable1.putClientProperty("terminateEditOnFocusLost", true); adding ta FocusListener to JTable in TableCellEditor and cancel editing when focus lost give a chance to check if the JDateChooser's popup is visible or not. But before this, JDateChooser should be extended with a popup isVisible method. Because popup variable is protected. And cell editor components should not be focusable else JTable also loses its focus