Since you neither linked to, nor named the JCalendar
implementation that you are using, I assume it is JCalendar by Kai Tödter. - At least what I can tell from your screenshot.
Using the component is fairly simple, this example should do:
import java.awt.EventQueue;
import javax.swing.JFrame;
import com.toedter.calendar.JCalendar;
public class Demo {
private JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Demo window = new Demo();
window.frame.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Demo() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JCalendar calendar = new JCalendar();
calendar.setBounds(20, 20, 200, 20);
frame.getContentPane().add(calendar);
}
}
Unfortunately, you also did not provide the code you use for initialization of the component. You can call the JCalendar
constructor either without parameters, passing a Date
object, a Calendar
object, a Locale
object or various combinations of the before mentioned.
Here is a complete list of valid constructors:
public JCalendar()
public JCalendar(Date date)
public JCalendar(Calendar calendar)
public JCalendar(Locale locale)
public JCalendar(Date date, Locale locale)
public JCalendar(Date date, boolean monthSpinner)
public JCalendar(Locale locale, boolean monthSpinner)
public JCalendar(boolean monthSpinner)
public JCalendar(Date date, Locale locale, boolean monthSpinner, boolean weekOfYearVisible)
To determine the user's selection, you can call getCalendar()
or getDate()
. To set an initial date, use setCalendar()
or setDate()
respectively. Hope that gets you started. If you have any problems, feel free to edit your question or leave a comment.
Also, did you check the sample project contained in the JCalendar ZIP file?