How to set “off” all the toogle day buttons in jCalendar?

谁说胖子不能爱 提交于 2019-12-08 07:24:33

问题


I'm using the toedter's jCalendar and triggering events when the day buttons are clicked using the following code:

  JDayChooser jdc = jCalendar.getDayChooser();
  jdc.addPropertyChangeListener("day", new PropertyChangeListener() {
       @Override
       public void propertyChange(PropertyChangeEvent e) {
           date = jCalendar.getDate();
           new AgendaFrame(date, user).setVisible(true);  
       } 
  }); 

The thing is that when jCalendar initiates, the button which matches the current date is already pressed and so, I'm unable to press it to go to my agenda frame. Any ideas to solve this?


回答1:


The thing is that when jCalendar initiates, the button which matches the current date is already pressed and so, I'm unable to press it to go to my agenda frame. Any ideas to solve this?

To solve this problem you have to use setAlwaysFireDayProperty(boolean alwaysFire) method to set this property true:

JCalendar calendar = new JCalendar();        
JDayChooser dayChooser = calendar.getDayChooser();
dayChooser.setAlwaysFireDayProperty(true); // here is the key
dayChooser.addPropertyChangeListener("day", ...);

This way if you press some button (for instance, today) the property event will be fired regardless the button was already pressed.

public void setAlwaysFireDayProperty(boolean alwaysFire)

this is needed for JDateChooser.

Parameters:

alwaysFire - true, if day property shall be fired every time a day is chosen.



来源:https://stackoverflow.com/questions/20337604/how-to-set-off-all-the-toogle-day-buttons-in-jcalendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!