package application; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; public class Controller { @FXML ImageView myView; Button myButton; Image myImage = new Image(getClass().getResourceAsStream("back.jpg")); //method that change our image public void displayImage() { myView.setImage(myImage); } }
<?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.AnchorPane?> <AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171"> <children> <AnchorPane layoutX="-6.0" prefHeight="421.0" prefWidth="518.0"> <children> <Button fx:id="myButton" layoutX="230.0" layoutY="322.0" mnemonicParsing="false" onAction="#isplayImage" prefHeight="70.0" prefWidth="105.0" text="Button" /> <ImageView fx:id="myView" fitHeight="228.0" fitWidth="290.0" layoutX="138.0" layoutY="39.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../../../Desktop/front.jpg" /> </image> </ImageView> </children> </AnchorPane> </children> </AnchorPane>
mnemonicParsing="false" onAction="#isplayImage" prefHeight="70.0"
displayImage
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)