public class CalendarTest2 extends JFrame {
private static final long serialVersionUID = 1L;
public CalendarTest2() {
Calendar cal = Calendar.getInstance();
JCalendar jCalendar1 = new JCalendar();
cal.setTime(jCalendar1.getDate());
int dayToBeSelected = cal.get(Calendar.DAY_OF_MONTH);
dayToBeSelected = 21;
JPanel jpanel = jCalendar1.getDayChooser().getDayPanel();
Component compo[] = jpanel.getComponents();
for (Component comp : compo) {
if (!(comp instanceof JButton))
continue;
JButton btn = (JButton) comp;
if (btn.getText().equals(String.valueOf(dayToBeSelected)))
comp.setBackground(Color.red);
}
add(jpanel);
}
public static void main(String[] args) {
CalendarTest2 test = new CalendarTest2();
test.setVisible(true);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(800, 800);
}
}
代わりの「ボタンを選択するための」によるインデックス、 てボタンにアクセスしようとするアクセスを選択していますテキスト(日番号)が記載されています。理由は、月のカレンダーは、7x7ファッションで配置された49個のボタンを使用して表示されます
です。 例)インデックス0は常に「日曜日」ボタンを指します。
ありがとうございます。しかし、私はこれが選択された日付のインデックスを取得するとは思わない。選択したアイテムを色付けしようとしています。 – Reyfik
ああ..選択した日のボタンの色を変更しますか? – Nandha
はい私はそれを意味する – Reyfik