有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Netbeans表示属性值不存在

根据Oracles自己的网站,我这样做是对的。但当我在Netbeans中执行此操作时,我会得到一个错误,该错误表示:类不存在PropertyValueFactory。有办法解决这个问题吗

    <TableView fx:id = "customerTable"  prefWidth ="270" prefHeight = "400" layoutX = "350" >
        <columns>
            <TableColumn text = "Utility">
                <cellValueFactory>
                    <PropertyValueFactory property="lastName" />

                </cellValueFactory>
            </TableColumn>


        </columns>



    </TableView>

共 (1) 个答案

  1. # 1 楼答案

    没关系,您只需导入以下内容:

    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.control.TableColumn?>
    <?import javafx.scene.control.cell.PropertyValueFactory?>
    

    所以,在你的FXML文件中

    <?xml version="1.0" encoding="UTF-8"?>
    <... other imports ...>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.control.TableColumn?>
    <?import javafx.scene.control.cell.PropertyValueFactory?>
    
    
    <BorderPane prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="FXMLDocumentController">
    ....
    <TableView fx:id = "customerTable"  prefWidth ="270" prefHeight = "400" layoutX = "350" >
            <columns>
                <TableColumn text = "Utility">
                    <cellValueFactory>
                        <PropertyValueFactory property="lastName" />
                    </cellValueFactory>
                </TableColumn>
            </columns>
        </TableView>
    ...
    </BordePane>
    

    会解决这个问题