Different styles in DateComboBox

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Different styles in DateComboBox

Postby gokulanand » Mon May 23, 2011 6:41 am

Hello Team,

I was going through DateComboBoxDemo from JIDE examples. With the "WeekDayOnly" datefilter, I could see only the weekdays are enabled and weekends are disabled. This means the user will not be able to select Weekend dates at all.

All I wanted is to differentiate weekdays from weekends ( with the help of "WeekdayOnly" dateFilter ) and also user should be able to pick any day of his wish ( including weekends ). Is that possible to do this ?

Thanks
gokulanand
 
Posts: 6
Joined: Fri Apr 29, 2011 4:11 am

Re: Different styles in DateComboBox

Postby JIDE Support » Mon May 23, 2011 8:45 am

Please use the following code to override DateComboBox.
Code: Select all
        new DateComboBox() {
            @Override
            protected DateChooserPanel createDateChooserPanel() {
                return new DateChooserPanel(getDateModel(), isShowTodayButton(), isShowNoneButton(), isShowWeekNumbers(), getLocale()) {
                    @Override
                    protected void updateDateLabel(JComponent dateLabel, Calendar date, boolean isSelected, boolean isToday, boolean withinCurrentMonth) {
                        super.updateDateLabel(dateLabel, date, isSelected, isToday, withinCurrentMonth);
                        if (isHoliday(date)) { // take your logic to decide which date you want to change color
                            dateLabel.setOpaque(true);
                            ((JideButton) dateLabel).setBackgroundOfState(ThemePainter.STATE_DEFAULT, Color.gray);
                        }
                    }
                };
            }
        }

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Different styles in DateComboBox

Postby gokulanand » Mon May 23, 2011 11:54 pm

Great. It worked. Thanks a lot.
gokulanand
 
Posts: 6
Joined: Fri Apr 29, 2011 4:11 am

Re: Different styles in DateComboBox

Postby onlyhuman » Thu Jul 17, 2014 1:02 am

Hi,

I've used this code to disable weekday labels and it is working for a single click, but for double clicks it is still selecting a weekday. I've tried to add a mouse listener to dateLabel and consume it when clickCount was 2, but it did not work. Do you have any idea how can I omit double clicks?
Thanks in advance!

Best regards,
Robert
onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am

Re: Different styles in DateComboBox

Postby JIDE Support » Thu Jul 17, 2014 8:57 am

I am not quite sure. If you override createDateLabel to create your own label and add your own mouse listener, double click shouldn't handled. Could you try to reproduce it by making a simple test case so that I can compile and run?
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Different styles in DateComboBox

Postby onlyhuman » Mon Feb 16, 2015 1:23 am

Sorry for the late reply, here is a sample code that you can compile. I did not add a mouse listener to consume double clicks but it is not working in this way either. I am using JIDE version 2.4.5
Code: Select all
package test;

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jidesoft.combobox.DateChooserPanel;
import com.jidesoft.combobox.DateComboBox;
import com.jidesoft.plaf.basic.ThemePainter;
import com.jidesoft.swing.JideButton;

public class DateComboboxTestMain extends JPanel {

   private final class DateComboBoxExtension extends DateComboBox {

      /**
       *
       */
      private static final long serialVersionUID = 1L;
      
      @Override
      public com.jidesoft.combobox.PopupPanel createPopupComponent() {
         return new DateChooserPanel(getDateModel(),
               isShowTodayButton(), isShowNoneButton(),
               isShowWeekNumbers(), getLocale()) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void updateDateLabel(JComponent dateLabel, Calendar date, boolean isSelected, boolean isToday, boolean withinCurrentMonth) {
               super.updateDateLabel(dateLabel, date, isSelected, isToday, withinCurrentMonth);

               if (isDateOnDay(date, Calendar.MONDAY) || isDateOnDay(date, Calendar.SUNDAY)) {
                   dateLabel.setOpaque(true);
                   ((JideButton) dateLabel).setBackgroundOfState(ThemePainter.STATE_DEFAULT, Color.lightGray);
                   ((JideButton) dateLabel).setEnabled(false);
               }
               
            }

            private boolean isDateOnDay(Calendar date, int dow) {
               int dayOfWeek = date.get(Calendar.DAY_OF_WEEK);
                     
               return dayOfWeek == dow;
            }

         };
      }
   
   }
   
   /**
    *
    */
   private static final long serialVersionUID = 1L;

   private DateComboBoxExtension dateCombo = new DateComboBoxExtension();

   public DateComboboxTestMain() {
    add(dateCombo, BorderLayout.PAGE_START);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
   }

   public static void main(String[] args) {
      // Schedule a job for the event-dispatching thread:
      // creating and showing this application's GUI.
      javax.swing.SwingUtilities.invokeLater(new Runnable() {

         public void run() {
            createAndShowGUI();
         }
      });
   }

   private static void createAndShowGUI() {
      JFrame frame = new JFrame("DateComboboxDemo");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JComponent newContentPane = new DateComboboxTestMain();
      newContentPane.setOpaque(true);
      frame.setContentPane(newContentPane);

      frame.pack();
      frame.setVisible(true);
   }

}

onlyhuman
 
Posts: 6
Joined: Mon Apr 04, 2011 7:51 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 9 guests

cron