如何在java日历中禁用日期范围

时间:2013-09-13 03:54:56

标签: java json calendar

在我的java项目中,我想在java日历中禁用一系列日期,但无法成功。我使用Netbeans作为我的IDE和JCalendar。以下是我的代码。任何帮助将不胜感激。

        ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();

        for (int i = 0; i < n; i++) {
            JSONObject another_json_object = vacation_home_booking_data.getJSONObject(i);

            JSONObject[] jsons = new JSONObject[arrays.size()];
            arrays.toArray(jsons);
            String id = another_json_object.getString("id");
            String vh_id = another_json_object.getString("vh_id");
            String check_in = another_json_object.getString("check_in");
            String check_out = another_json_object.getString("check_out");
            String status = another_json_object.getString("status");
            //creating two arrays of checking and checkout
            //check_in_arr[i] = another_json_object.getString("check_in");
            //check_out_arr[i] = another_json_object.getString("check_out");
            System.out.println("ID is " + id + "vh id is " + vh_id + "check in is " + check_in + "check out is " + check_out);


             DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
             try {
             Date date1 = formatter.parse(check_in);
             Date date2 = formatter.parse(check_out);

             jCalendar1.setSelectableDateRange(date1, date2);
             jCalendar1.setBackground(Color.yellow);


             //jCalendar1.setSelectedDate();
             } catch (ParseException ex) {
             Logger.getLogger(Calender.class.getName()).log(Level.SEVERE, null, ex);
             ex.printStackTrace();
             }


        }

1 个答案:

答案 0 :(得分:0)

如果以下方法适合您,请参阅:

  private DateChooserCombochooser; // Initialize this somewhere
  public void setMaxDate(Calendar aDate) {
        chooser.setMaxDate(aDate);
    }

    public void setMinDate(Calendar aDate) {
        chooser.setMinDate(aDate);
    }

或者,尝试在API中使用setDefaultPeriods(PeriodSet periods)方法。