为什么我的背景图像不以FXML显示 [英] Why isn't my background image being displayed in FXML
问题描述
我决定开始学习FXML,我想要做的第一件事就是创建一个背景图像。我之前在javafx中添加了背景图像,我认为在FXML中添加背景图像的过程与javafx中的相似。我缺少什么?
I decided that I wanted to start learning FXML and the first thing that I wanted to do is create a background Image. I've added background images in javafx before and I thought that the process of adding background images in FXML would what somewhat similar to what you would do in javafx. What am I missing?
这是我的FXML文件
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox fx:id="menu" spacing = "20" alignment="TOP_CENTER" xmlns:fx="http://javafx.com/fxml/1" fx:controller="millionairetriviagame.MenulayoutFXMLController">
<StackPane>
<ImageView>
<image>
<Image url="@ImageFiles/BlueBackgroundColor.jpg" />
</image>
</ImageView>
</StackPane>
</VBox>
我在javafx的主要课程
My main class in javafx
public class MillionaireTriviaGame extends Application
{
@Override
public void start(Stage menuStage) throws Exception
{
Parent object = FXMLLoader.load(getClass().getResource("MenulayoutFXML.fxml"));
Scene menuScene = new Scene(object, 640, 480);
menuStage.setTitle("Let's play who wants to be a millionaire");
menuStage.setScene(menuScene);
menuStage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
我的项目目录(我正在工作的项目) with is MillionaireTriviaGame)
My project directory(The project that I'm working with is MillionaireTriviaGame)
推荐答案
您的项目目录显示您的图片文件夹位于 ImageFiles
文件夹中不在类路径上。由于这在运行时,应用程序无法找到图像。
Your project directory shows that your image folder is located in a folder ImageFiles
which is not on the classpath. Due to this at runtime, the application is not able to find the image.
将文件夹 ImageFiles
移动到 src
,清理并构建项目并尝试再次运行。
Move the folder ImageFiles
into src
, clean and build the project and try to run again.
这篇关于为什么我的背景图像不以FXML显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!