0

this is the preview in scene builder preview

below is the fxml code

 <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="452.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
   <center>
      <ImageView fitHeight="187.0" fitWidth="372.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
         <image>
            <Image url="@../../../../java/testImages/testImage.jpeg" />
         </image>
      </ImageView>
   </center>
   <bottom>
      <Button mnemonicParsing="false" text="Button" BorderPane.alignment="CENTER" />
   </bottom>
</BorderPane>

the image below is the executed code result where the image should appear

inline

below is the java code

package com.ultijavafx.ultijavafx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class jfx extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(jfx.class.getResource("javafxVeiw.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 1500, 1000);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

the image below is the resource structure

resource

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • 1
    Images are resources, not java code. Put them in the resource directory and adjust you lookup paths accordingly. Usually build tools will create classes from Java files and copy resources from the resources directory to the build output. But the "java" directory isn't going to be in the build output and there build tools might not copy stuff under the java directory to the build output anyway. Study and follow some of the suggestions from the [eden JavaFX resource guide](https://edencoding.com/where-to-put-resource-files-in-javafx/). – jewelsea Nov 03 '22 at 08:37
  • 1
    Related: [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other) – jewelsea Nov 03 '22 at 08:39
  • You spelt view wrong, it's consistently wrong, so its not wrong, but its wrong. – jewelsea Nov 03 '22 at 08:44
  • so i should spell view correctly and my code will work right – maxwell Owusu Nov 03 '22 at 11:37
  • 1
    No the mispelling is not the cause of the failure, because you use the same value everywhere. The cause is the incorrect path and placement of the images. – jewelsea Nov 03 '22 at 12:44
  • i have checked the link though i have done it already last week in eclipse and it's working but it's not working in intellij and i want to know why if you can help – maxwell Owusu Nov 03 '22 at 18:14
  • Your setup in the question is not as referenced in the linked articles. Have you moved the images directory under resources and fixed the paths in the fxml to point to the updated location as recommended? If so, what is the new path to the image directory? You can edit the question to update it with new info. – jewelsea Nov 03 '22 at 20:58

0 Answers0