java - Why isn't my background image being displayed in FXML -
i decided wanted start learning fxml , first thing wanted create background image. i've added background images in javafx before , thought process of adding background images in fxml similar in javafx. missing?
here fxml file
<?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>
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 wants millionaire"); menustage.setscene(menuscene); menustage.show(); } public static void main(string[] args) { launch(args); } }
my project directory(the project i'm working millionairetriviagame)
your project directory shows image folder located in folder imagefiles
not on classpath. due @ runtime, application not able find image.
move folder imagefiles
src
, clean , build project , try run again.