简体   繁体   English

JavaFX Tableview 排序 java.sql.Date 列,Z37A6259CC0C1DAE299A7866649 底部升序排列

[英]JavaFX Tableview sort java.sql.Date column with null at bottom on ascending order

I have a column that contains java.sql.Date and I want it to put nulls at the bottom in ascending order:我有一列包含 java.sql.Date ,我希望它按升序将空值放在底部:

在此处输入图像描述

Right now, they end up on top.现在,他们最终处于领先地位。

 followupCol.setCellFactory((TableColumn<DisabilityCase, Date> p) ->
        {
            TableCell<DisabilityCase, Date> cell = new TableCell<DisabilityCase, Date>()
            {
                @Override
                protected void updateItem(Date item, boolean empty)
                {
                    super.updateItem(item, empty);
                    if (item == null || empty)
                    {
                        setText(null);
                    } else
                    {
                        if (!LocalDate.now().isBefore(item.toLocalDate()))
                        {
                            setTextFill(Color.RED);
                        } else
                        {
                            setTextFill(Color.BLACK);
                        }

                        setText(new SimpleDateFormat(DATE_FORMAT).format(item));
                    }
                }

            };


            return cell;
        });

Since java.sql.Date is already Comparable , you can use由于java.sql.Date已经是Comparable ,您可以使用

followupCol.setComparator(Comparator.nullsLast(Comparator.naturalOrder()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM