0

In my java project i want to disable a range of dates in the java calendar and could not be successful. I'm using Netbeans as my IDE and JCalendar. Below is my code. Any help would be appreciated.

        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();
             }


        }
belekka
  • 66
  • 2
  • 13

1 Answers1

0

Please see, if the below methods works for you:

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

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

Alternatively, try using setDefaultPeriods(PeriodSet periods) method in the API.

Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53