public void openPopup ( ) { if ( isPopupOpen ( ) ) { closePopup ( ) ; return ; } if ( settings == null ) { return ; } // If the component is disabled, do nothing. if ( ! isEnabled ( ) ) { return ; } // If this function was called programmatically, we may need to change the focus to this // popup. if ( ! dateTextField . hasFocus ( ) ) { dateTextField . requestFocusInWindow ( ) ; } // Get the last valid date, to pass to the calendar if needed. LocalDate selectedDateForCalendar = lastValidDate ; // Create a new calendar panel. // Use the CalendarPanel constructor that is made for the DatePicker class. DatePicker thisDatePicker = this ; calendarPanel = new CalendarPanel ( thisDatePicker ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . PREVIOUS_YEAR , calendarPanel . getPreviousYearButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . PREVIOUS_MONTH , calendarPanel . getPreviousMonthButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . NEXT_MONTH , calendarPanel . getNextMonthButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . NEXT_YEAR , calendarPanel . getNextYearButton ( ) ) ) ; // If needed, apply the selected date to the calendar. if ( selectedDateForCalendar != null ) { calendarPanel . setSelectedDate ( selectedDateForCalendar ) ; } // Create a new custom popup. popup = new CustomPopup ( calendarPanel , SwingUtilities . getWindowAncestor ( this ) , this , settings . getBorderCalendarPopup ( ) ) ; // Calculate the default origin for the popup. int defaultX = toggleCalendarButton . getLocationOnScreen ( ) . x + toggleCalendarButton . getBounds ( ) . width - popup . getBounds ( ) . width - 2 ; int defaultY = toggleCalendarButton . getLocationOnScreen ( ) . y + toggleCalendarButton . getBounds ( ) . height + 2 ; // Determine which component to use as the vertical flip reference component. JComponent verticalFlipReference = ( settings . getVisibleDateTextField ( ) ) ? dateTextField : toggleCalendarButton ; // Set the popup location. zSetPopupLocation ( popup , defaultX , defaultY , this , verticalFlipReference , 2 , 6 ) ; // Show the popup and focus the calendar. popup . show ( ) ; calendarPanel . requestFocus ( ) ; }
openPopup This opens the calendar popup .