JavaFX FXML加载

时间:2017-11-16 08:13:25

标签: java javafx fxml

我的Java代码应该加载包含一些FlowPane的fxml:

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

<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.FlowPane?>
<FlowPane fx:id="listView" prefHeight="248.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.ProjectDetail">
          <Label fx:id="labelOpisRadnje" layoutX="14.0" layoutY="14.0" text="Label" />
          <Hyperlink fx:id="linkDatoteka" layoutX="13.0" layoutY="63.0" text="Datoteka" />
</FlowPane>

这是我的控制者:

if (details.size() > 0) {
                listViewProjectDetails.setPrefSize(700.0, 300.0);
                listViewProjectDetails.setItems(details);
                listViewProjectDetails.setCellFactory(param -> new ListCell<model.ProjectDetails>() {

                    private Node graphic;
                    private ProjectDetail controller;
                    {
                        FXMLLoader loader = new FXMLLoader(getClass().getResource("../view/ProjectDetail.fxml"));
                        try {
                            graphic = loader.load();
                            controller = loader.getController();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    }
                    @Override
                    protected void updateItem(model.ProjectDetails item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item != null) {
                            controller.setLabelOpisRadnje(item.getOpisRadnje());
                            controller.setLabelOpisRadnje("Project id: " + item.getProject());
                            controller.setLinkDatoteka(item.getFile(), item.getFilenamePrefix(), item.getFilenameSufix());
                            setGraphic(graphic);
                        }
                    }
                });

                nodes.add(listViewProjectDetails);
                selected = tab;
            } else {
                FXMLLoader loader = new FXMLLoader(getClass().getResource("../view/ProjectDetailsEmpty.fxml"));
                nodes.add(loader.load());
            }

问题是这个setCellFactory没有被触发,根本没有加载。我不明白为什么?

0 个答案:

没有答案