javafxjfxtras

JavaFX JFXtras CalendarTextField withShowTime


I feel that I am missing something when using the CalendarTextField so I come here for some help. Here is the SSCCE that I am using:

Main.java:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("CalendarTextFieldTest.fxml"));
            Scene scene = new Scene((StackPane) loader.load());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

CalendarTextFieldTest.fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.StackPane?>
<?import jfxtras.scene.control.CalendarTextField?>

<StackPane xmlns:fx="http://javafx.com/fxml/1" prefWidth="200" fx:controller="com.example.test.CalendarTextFieldTestController">
    <CalendarTextField fx:id="test"/>
</StackPane>

CalendarTextFieldController.java:

package com.example.test;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javafx.fxml.FXML;
import jfxtras.scene.control.CalendarTextField;

public class CalendarTextFieldTestController {
    @FXML
    CalendarTextField test;

    public void initialize()
    {
        test.withCalendar(Calendar.getInstance());
        //test.withShowTime(Boolean.TRUE);
        test.setDateFormat(SimpleDateFormat.getDateTimeInstance());
    }
}

In this state the test works fine. But when I comment out the test.showShowTime(Boolean.TRUE) I no longer get any type of response when clicking a date.

Any help as to what I may be overlooking would be appreciated.


Solution

  • I just ran your example and it runs flawlessly, so it is not a bug in JFXtras, it seems.

    Maybe you are over looking the two icons in the top right corner? That is, if you use the latests R4-SNAPSHOT, because JavaFX has made some changes to the way they do CSS in 8.20 and those icons are not visible with earlier versions.

    Problem with the "show time mode" is that when the time sliders are shown, there are suddenly multiple active buttons to press and slide around. If only date is shown, the popup knows it can close when a date is clicked. But in time mode it cannot; maybe the user still wants to modify the hours, or minutes, or maybe not. There is no way of telling. So in time mode there is an explicit accept or cancel icon in the top right corner.