set Date Format to JavaFX Table Column - Java JavaFX

Java examples for JavaFX:Date Picker

Description

set Date Format to JavaFX Table Column

Demo Code


    //package com.java2s;
    import java.text.DateFormat;

    import java.util.Date;

    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;

    public class Main {
        public static void setDateFormatColumn(TableColumn dateColumn, int dateFormat) {
    DateFormat format = DateFormat.getDateInstance(dateFormat);
    dateColumn.setCellFactory(myDateTableCell -> {
        return new TableCell<Object, Date>() {
            @Override//from  w w  w .  ja va 2  s  . c o m
            protected void updateItem(Date date, boolean dateIsEmpty) {
                super.updateItem(date, dateIsEmpty);
                if (date == null || dateIsEmpty) {
                    setText(null);
                } else {
                    setText(format.format(date));
                }
            }
        };
    });        
}
    }

Related Tutorials