Extreme Component

ComponentSet Programmer Guide > JCalendar

JCalendar - Java Date Picker

JCalendar provides a Java calendar component, a Java date picker.

Header Style

JCalendar provides three header styles: class arrow, modern arrow, none.

Code Samples:

// create JCalendar component
JCalendar calendar = new JCalendar();
// classic arrow
calendar.putClientProperty("JCalendar.headerStyle", "Classic_Arrow");
// modern arrow
calendar.putClientProperty("JCalendar.headerStyle", "Modern_Arrow");
// none
calendar.putClientProperty("JCalendar.headerStyle", "None");

Center Style

JCalendar provides two center styles: month view, year view.

Code Samples:

// create JCalendar component
JCalendar calendar = new JCalendar();
// month view
calendar.putClientProperty("JCalendar.centerStyle", "MonthView");
// year view
calendar.putClientProperty("JCalendar.centerStyle", "YearView");

Footer Style

JCalendar provides two footer styles: today, none.

Code Samples:

// create JCalendar component
JCalendar calendar = new JCalendar();
// show today button
calendar.putClientProperty("JCalendar.footerStyle", "Today");
// hide the today button
calendar.putClientProperty("JCalendar.footerStyle", "None");

Highlight Date

JCalendar supports highlight date, you can change the date background and foreground. The following code will change the date 1, 3, 5, 7, 23 foreground and background, sets the foreground to red, and background to yellow.

Code Samples:

// a sample AttributesProvider
    private static class DefaultAttributesProvider implements AttributesProvider {
	private SimpleAttributeSet a;
	public DefaultAttributesProvider() {
	    a = new SimpleAttributeSet();
	    StyleConstants.setForeground(a, Color.red);
	    StyleConstants.setBackground(a, Color.yellow);
	}
	public AttributeSet getAttributes(Object value) {
	    if(value != null) {
		int day = ((Integer)value).intValue();
		switch(day) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 23:
		    return a;
		}
	    }
	    return null;
	}
    }
// attach it to JCalendar component
JCalendar calendar = new JCalendar();
calendar.setCellProvider(new DefaultAttributesProvider());    

Change Date Font

JCalendar component also supports the different date font. The following code will change the date 1, 3, 5, 7, 23 font, sets the font family to "Dialog", font size to 20 and font style to bold.

Code Samples:

// a sample AttributesProvider
    private static class DefaultAttributesProvider implements AttributesProvider {
	private SimpleAttributeSet a;
	public DefaultAttributesProvider() {
	    a = new SimpleAttributeSet();
	    StyleConstants.setFontFamily(a, "Dialog");
	    StyleConstants.setFontSize(a, 20);
	    StyleConstants.setBold(a, true);
	}
	public AttributeSet getAttributes(Object value) {
	    if(value != null) {
		int day = ((Integer)value).intValue();
		switch(day) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 23:
		    return a;
		}
	    }
	    return null;
	}
    }
// attach it to JCalendar component
JCalendar calendar = new JCalendar();
calendar.setCellProvider(new DefaultAttributesProvider());    


Copyright (c) zfqjava.com
All rights reserved.