有 Java 编程相关的问题?

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

javafx中的java自定义控件

我在JavaFX中创建了一个自定义AnchorPane(ItemCard),以便在另一个FXML文件中使用它

项目卡。fxml文件

    <?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>

ItemCard的控制器是:

import java.io.IOException;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;

/**
 *
 * @author ola
 */
public class ItemCard extends AnchorPane {

    @FXML
    ImageView ItemCardView;
    @FXML
    AnchorPane ItemCardPane;

    public ItemCard() {

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ItemCard.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();

        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }

    public void setImage(Image image) {
        ItemCardView.setImage(image);
//        getChildren().add(ItemCardView);
    }

}

我想在另一个fxml中使用此itemCard锚定窗格。 家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>

但问题是,当我打开家。fxml使用场景生成器无法查看项目卡。 错误是; 在javafx。fxml。FXMLLoader。constructLoadException(FXMLLoader.java:2617)


共 (0) 个答案