2
コードhereに続いてToadterのCalendar
で特定の日付の色を設定しました。私が直面している問題は、正しいセルを強調していないということです。私の例では、6月14日と15日を使いましたが、8日と9日にハイライトされました。JCalendarセルの特定の日付を強調表示するJava
そして相続人マイコード:成分を変更することの代替として
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date sdate= null;
String d = null;
for(int i =0;i<pd.size();i++){
d = pd.get(i).getDate();
try{
sdate = (Date)formatter.parse(d);
if(events.contains(sdate)){
}
else{
events.add(sdate);
System.out.println(sdate);
}
}catch(ParseException r){
System.out.println("error");
}
}
//arraylist of events
for(int i = 0; i < events.size(); i++)
{
Calendar cal1 = Calendar.getInstance();
cal1.setTime(events.get(i));
int day1 = cal1.get(Calendar.DAY_OF_MONTH);
int month1 = cal1.get(Calendar.MONTH);
int year1 = cal1.get(Calendar.YEAR);
//selected month and year on JCalendar
if(month == month1 && year == year1)
{
// Calculate the offset of the first day of the month
cal.set(Calendar.DAY_OF_MONTH,1);
int offset = cal.get(Calendar.DAY_OF_WEEK) -1;
component[day1 + offset ].setBackground(Color.blue);
}
}