javafx中的自定义控件
我在JavaFX中创建了一个自定义AnchorPane项目卡,以便在另一个FXML文件中使用它 ItemCard.fxml文件javafx中的自定义控件,java,javafx-8,fxml,Java,Javafx 8,Fxml,我在JavaFX中创建了一个自定义AnchorPane项目卡,以便在另一个FXML文件中使用它 ItemCard.fxml文件 <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <fx:root type="AnchorPane"
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<fx:root type="AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane fx:id="ItemCardPane" prefHeight="360.0" prefWidth="266.0" stylesheets="@ItemCard.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ImageView fx:id="ItemCardView" fitHeight="399.0" fitWidth="245.0" layoutX="11.0" layoutY="6.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" BorderPane.alignment="CENTER" />
</children>
</AnchorPane>
</children>
</fx:root>
我想在另一个fxml中使用此itemCard锚定窗格。
home.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import com.syrianep.reader.ui.KidsTheme.resources.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="home" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1000.0" prefWidth="1250.0" style="-fx-border-radius: 5; -fx-background-color: tranparant;" stylesheets="@mainView.css" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml" fx:controller="com.syrianep.reader.ui.KidsTheme.resources.HomeController" >
<children>
<ItemCard layoutX="50.0" layoutY="50.0"AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"/>
</children>
</AnchorPane>
但问题是,当我使用场景生成器打开home.fxml时,无法查看itemCard。
错误是;
在javafx.fxml.fxmloader.constructLoadExceptionfxmloader.java:2617,您是否也会收到错误消息,而不仅仅是错误所在的过程调用?如果您尝试加载包含自定义控件的FXML会发生什么?谢谢,我解决了这个问题。我在netbeans平台上使用javafx,所以我应该将模块的包作为公共包。
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import com.syrianep.reader.ui.KidsTheme.resources.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="home" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1000.0" prefWidth="1250.0" style="-fx-border-radius: 5; -fx-background-color: tranparant;" stylesheets="@mainView.css" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml" fx:controller="com.syrianep.reader.ui.KidsTheme.resources.HomeController" >
<children>
<ItemCard layoutX="50.0" layoutY="50.0"AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"/>
</children>
</AnchorPane>