Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing JXDatePicker

Tags:

java

swing

swingx

I'm using SwingX JXDatePicker and I can't figure out how to provide next/previous year buttons (as by default it only provides next/previous month buttons).

Also, it seems that SwingX is not maintained anymore: should I be using a more recent component as date picker?

Any help/hint would be greatly appreciated. Thanks, Thomas

UPDATE:

To clarify the question, I added a JXDatePicker screenshot and highlighted in red the next/previous month buttons. The questions is thus: how to add buttons that will bring the calendar to next/previous year? Please note that the new buttons need to be standard components as they need to be rendered by a particular Look & Feel manager (Insusbtantial in this case).

Many thanks

enter image description here

like image 892
Tom Avatar asked Apr 19 '13 19:04

Tom


2 Answers

I know this is an old question, but I finally found the answer here, from kleopatra's comment about SwingsLab demo.

The SwingsLab demo provides an example of how to set a custom calendar header on a per-component basis, but this is the code I actually used (this is global; per-application):

UIManager.put(CalendarHeaderHandler.uiControllerID, SpinningCalendarHeaderHandler.class.getName());
datePicker = new JXDatePicker();
datePicker.getMonthView().setZoomable(true); //this is needed for custom header

This seems to be experimental code (not fully public yet), so use at own risk. Hope it helps.

SwingsLab Demo

like image 190
Radiance Wei Qi Ong Avatar answered Sep 20 '22 14:09

Radiance Wei Qi Ong


I would recommend using Microba DatePicker. It's highly customizable and does exactly what you want.

http://microba.sourceforge.net/

enter image description hereenter image description here

Edit:

Ok I see. Well I did some research and it seems the function you are looking for is actually not present in JXDatePicker.

A different alternative I found is: JDatePicker at http://sourceforge.net/projects/jdatepicker/.

Main website: https://jdatepicker.org/

This is still supported and seems to have the function you want.

like image 29
Omid Avatar answered Sep 17 '22 14:09

Omid