TableView列中未显示日期数据

如何解决TableView列中未显示日期数据

我正在用JavaFX制作一个小项目,该项目将人员及其各自的食品订单添加到列表中,到目前为止,除了上述列表中的“ fecha”列外,它的工作都令人惊奇。应该可以接收到接受订单后的当前本地日期和时间,但不能接受。

这是主要班级:

public class App extends Application {

    private static Scene scene;
    private static Stage stageAux; // Copia auxiliar de Stage,para uso en métodos menores

    @Override
    public void start(Stage stage) throws IOException {
        stageAux = stage;
        scene = new Scene(loadFXML("primary"),1200,720);
        stage.setScene(scene);
        stage.setTitle("Comandas Desayuno");
        stage.show();
    }

    static void setRoot(String fxml) throws IOException {
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    public static void main(String[] args) {
        launch();
    }
    
    public boolean fullscreen(){
        stageAux.setFullScreen(!stageAux.isFullScreen());
        return stageAux.isFullScreen();
    }

}

这是主控制器:

public class PrimaryController implements Initializable {

    private Connection con;
    private Statement stat;
    private ObservableList<Pedidos> pedidosList;
    private Pedidos pedidoSeleccionado;
    private Integer seleccion;
    
    private int id = 1; // Contador de id de cada cliente
    
    // SimpleDateFormat y Date para coger la hora a la que se ha hecho el pedido
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");  
    Date currentDate = new Date();
    
    private App app = new App();
    private Functions f1 = new Functions();

    @FXML
    private MenuItem menuFileClose;
    @FXML
    private TableView<Pedidos> tablaId;
    @FXML
    private TableColumn<Pedidos,Integer> idColumn;
    @FXML
    private TableColumn<Pedidos,String> bebidaColumn;
    @FXML
    private TableColumn<Pedidos,String> comidaColumn;
    @FXML
    private TableColumn<Pedidos,String> clienteColumn;
    @FXML
    private TableColumn<Pedidos,Double> precioColumn;
    @FXML
    private TableColumn<Pedidos,Date> fechaColumn;
    @FXML
    private TableColumn<Pedidos,Boolean> entregaColumn1;
    @FXML
    private MenuItem fullscreenItem;
    @FXML
    private TextField clientName;
    @FXML
    private ChoiceBox<String> comidaBox;
    @FXML
    private ChoiceBox<String> bebidaBox;
    @FXML
    private Button saveButton;
    @FXML
    private Button deleteButton;
    @FXML
    private CheckBox entregadoCheck;
    @FXML
    private Label elementoLabel;
    @FXML
    private Button controlPanelButton;
    
    private void clearElement(){
        
        clientName.setText("");
        bebidaBox.getSelectionModel().select("Nada");
        comidaBox.getSelectionModel().select("Nada");
        entregadoCheck.setSelected(false);
        
    }
    
    private void editData(){
        
        elementoLabel.setText("Editar Elemento");
        
        f1.resetPrecioPedido();
        
        f1.setBebida(bebidaBox.getValue());
        f1.setComida(comidaBox.getValue());

        pedidoSeleccionado = new Pedidos(
            pedidoSeleccionado.getId(),bebidaBox.getValue(),comidaBox.getValue(),clientName.getText(),f1.getPrecioPedido(),currentDate,entregadoCheck.isSelected()
        ); 
   
        pedidosList.set(seleccion,pedidoSeleccionado);
        tablaId.refresh(); // Actualiza la tabla automáticamente
        tablaId.getSelectionModel().select(null); // Deselecciona la fila que se acaba de editar
        elementoLabel.setText("Nuevo Elemento");
    }
    
    // Guarda los pedidos nuevos / Actualiza los pedidos seleccionados(con editData())
    @FXML
    private void save(ActionEvent event) {
        
        f1.setBebida(bebidaBox.getValue());
        f1.setComida(comidaBox.getValue());

        Pedidos p = new Pedidos(
            id,entregadoCheck.isSelected()
        );
        
        if(pedidoSeleccionado == null){
            if(!pedidosList.contains(p)){
                pedidosList.add(p);
                id++;
            } 
        } else {
            editData();
        }
        
        f1.resetPrecioPedido();
        clearElement();
    }
    
    // Pone en pantalla los datos editables del pedido seleccionado
    @FXML
    private void seleccionar(MouseEvent event) {
        
        pedidoSeleccionado = tablaId.getSelectionModel().getSelectedItem();
        seleccion = tablaId.getSelectionModel().getSelectedIndex();
        
        clientName.setText(pedidoSeleccionado.getCliente());
        bebidaBox.getSelectionModel().select(pedidoSeleccionado.getBebida());
        comidaBox.getSelectionModel().select(pedidoSeleccionado.getComida());
        entregadoCheck.setSelected(pedidoSeleccionado.getEntregado());

    }
    
    @FXML
    private void delete(ActionEvent event) {

        Pedidos p = tablaId.getSelectionModel().getSelectedItem();
        pedidosList.remove(p);
    }
    
    @FXML
    private void close(ActionEvent event) {
        System.exit(0);
    }
    
    @FXML
    private void goFullscreen(ActionEvent event) {
        app.fullscreen();
    }
    
    @Override
    public void initialize(URL url,ResourceBundle rb){
        
        pedidosList = FXCollections.observableArrayList();
        tablaId.setItems(pedidosList);
        
        idColumn.setCellValueFactory(new PropertyValueFactory("id"));
        clienteColumn.setCellValueFactory(new PropertyValueFactory("cliente"));
        bebidaColumn.setCellValueFactory(new PropertyValueFactory("bebida"));
        comidaColumn.setCellValueFactory(new PropertyValueFactory("comida"));
        precioColumn.setCellValueFactory(new PropertyValueFactory("precio"));
        fechaColumn.setCellValueFactory(new PropertyValueFactory("fecha"));
        entregaColumn1.setCellValueFactory(new PropertyValueFactory("entregado"));
        
        // Lista completa de bebidas
        bebidaBox.getItems().addAll(
                "Nada","Café Solo - 0.8€","Café con Leche - 1€","Refresco - 1.5€","Colacao - 1.5€");
        bebidaBox.getSelectionModel().select("Nada");
        
        // Lista completa de comidas
        comidaBox.getItems().addAll(
                "Nada","Pitufo Mixto - 1.5€","Pitufo Bacon - 1.7€","Pitufo Lomo - 2€","Bocata Paté - 2.5€","Bocata Bacon - 3€","Bocata Chorizo - 3.5€");
        comidaBox.getSelectionModel().select("Nada");
    }    
}

这是“ Pedidos”类:

public class Pedidos {

    private int id;
    private String bebida;
    private String comida;
    private String cliente;
    private double precio;
    private Date currentDate;
    private Boolean entregado;

    public Pedidos() {
    }

    public Pedidos(int id,String bebida,String comida,String cliente,double precio,Date currentDate,boolean entregado) {
        this.id = id;
        this.bebida = bebida;
        this.comida = comida;
        this.cliente = cliente;
        this.precio = precio;
        this.currentDate = currentDate;
        this.entregado = entregado;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBebida() {
        return bebida;
    }

    public void setBebida(String bebida) {
        this.bebida = bebida;
    }

    public String getComida() {
        return comida;
    }

    public void setComida(String comida) {
        this.comida = comida;
    }


    public String getCliente() {
        return cliente;
    }

    public void setCliente(String cliente) {
        this.cliente = cliente;
    }

    public double getPrecio() {
        return precio;
    }

    public void setPrecio(double precio) {
        this.precio = precio;
    }

    public Date getCurrentDate() {
        return currentDate;
    }

    public void setCurrentDate(Date currentDate) {
        this.currentDate = currentDate;
    }

    public Boolean getEntregado() {
        return entregado;
    }

    public void setEntregado(Boolean entregado) {
        this.entregado = entregado;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pedidos other = (Pedidos) obj;
        if (this.id != other.id) {
            return false;
        }
        if (Double.doubleToLongBits(this.precio) != Double.doubleToLongBits(other.precio)) {
            return false;
        }
        if (!Objects.equals(this.bebida,other.bebida)) {
            return false;
        }
        if (!Objects.equals(this.comida,other.comida)) {
            return false;
        }
        if (!Objects.equals(this.cliente,other.cliente)) {
            return false;
        }
        if (!Objects.equals(this.currentDate,other.currentDate)) {
            return false;
        }
        if (!Objects.equals(this.entregado,other.entregado)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Pedidos{" + "id=" + id + ",bebida=" + bebida + ",comida=" + comida + ",cliente=" + cliente + ",precio=" + precio + ",currentDate=" + currentDate + ",entregado=" + entregado + '}';
    }
}

这是当我在列表中输入新人员时出现的终端输出:

WARNING: Can not retrieve property 'fecha' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@6f86016e with provided class type: class modelos.Pedidos
java.lang.IllegalStateException: Cannot read from unreadable property fecha
    at javafx.base/com.sun.javafx.property.PropertyReference.get(PropertyReference.java:170)
    at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.getCellDataReflectively(PropertyValueFactory.java:184)
    at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:154)
    at javafx.controls/javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:133)
    at javafx.controls/javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:593)
    at javafx.controls/javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:578)
    at javafx.controls/javafx.scene.control.TableCell.updateItem(TableCell.java:646)
    at javafx.controls/javafx.scene.control.TableCell.indexChanged(TableCell.java:469)
    at javafx.controls/javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
    at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:539)
    at javafx.controls/javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:159)
    at javafx.controls/javafx.scene.control.skin.TableRowSkin.<init>(TableRowSkin.java:89)
    at javafx.controls/javafx.scene.control.TableRow.createDefaultSkin(TableRow.java:213)
    at javafx.controls/javafx.scene.control.Control.doProcessCSS(Control.java:897)
    at javafx.controls/javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
    at javafx.controls/com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
    at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9540)
    at javafx.graphics/javafx.scene.Node.applyCss(Node.java:9627)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1749)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1726)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1852)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2755)
    at javafx.controls/javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1245)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1206)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1213)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1213)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1213)
    at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1213)
    at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
    at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2482)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:412)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:411)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:438)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:563)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:543)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:536)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:342)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)

这可能真的很愚蠢,但是我已经花了一段时间了,但我只是找不到如何使它起作用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-