This happens because when you call $this.datepicker() it only initializes the date picker without ever showing it up.

So if you click it again, that will be the time that the date picker will show itself since it was already initialized.

What you can do to show the date picker right away on first click is to call it like this:

That should do it.

Sad to say, there is no such control in Java FX 2. However, Java FX 8 has one. Then again, if you want to maintain your rule that you must never force the user to update to the latest version just to be able to see a date picker, the only option is to make one.

Luckily, somebody else did the dirty work for us. Marko Jacob extended a more flexible version from Christian Schudt and it works flawlessly. Plus, using it is fairly easy too.

The downside to this is that you cannot import this control in the Java FX Scene Builder. You will have to add the DatePicker control programmatically.

javafx-date-picker

Download his JavaFX Date Picker Release on GitHub.

I looked for a free Java date picker class so I do not have to make one of my own. That would simplify things. The one I found that is free is found in SourceForge or you can go directly to this website: http://opensource.theotherbell.com.

Using it is pretty easy. Just instantiate the class and that is it. It comes with 2 jar files: one for the datepicker and one called AbsoluteLayout.jar which is a custom class for NetBeans only. Based on that, the author of this date picker module used NetBeans as the development environment.

If you try to set a background color of the DateField class, you will notice extra spaces margins on the top and left (see photo).

This is ok if you show this component only. But if you place them with other components, the extra space will not align the date picker component together with the others. I did a simply and dirty hack to remove them. See code below.

Related Posts Plugin for WordPress, Blogger...