I have some code in Java fx controller class as below. The images are not showing up. Images are in place, no errors. Please guide.
@Override
public void initialize(URL location, ResourceBundle resources) {
image1 = new Image(getClass().getResource("php81e3DF.png").toExternalForm());
image2 = new Image(getClass().getResource("phpqJypee.png").toExternalForm());
image3 = new Image(getClass().getResource("php2XSnrZ.png").toExternalForm());
defaultt = new Image(getClass().getResource("phpxrxh4T.png").toExternalForm());
imgVw1 = new ImageView();
imgVw1.setX(200);
imgVw1.setY(200);
imgVw2 = new ImageView();
imgVw3 = new ImageView();
imgVw1.setImage(image1);
imgVw2.setImage(image2);
imgVw3.setImage(image3);
}
I am not able to make the images show up. I am sure the fxml and the controller class are using proper annotations. I used proper @fxml in the class and no errors with variables.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane fx:id="rootPane" alignment="TOP_CENTER" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<GridPane hgap="2.0" vgap="2.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<children>
<ImageView fx:id="imgVw1" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="imgVw2" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" />
<ImageView fx:id="imgVw3" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="2" />
<Button fx:id="imageV1Button" mnemonicParsing="false" onAction="#button1Pressed" text="Flip" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Button fx:id="imageV2Button" mnemonicParsing="false" onAction="#button1Pressed" text="Flip" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Button fx:id="imageV3Button" mnemonicParsing="false" onAction="#button1Pressed" text="Flip" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP" />
</children>
</GridPane>
</children>
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
</GridPane>