前提・実現したいこと
Scene BuliderのImageView内に表示される画像を、ソースコード内から変更したいのですが、
実行画面に何も表示されません。
該当のソースコード
Java
1package sample; 2import javafx.application.Application; 3import javafx.fxml.*; 4import javafx.scene.*; 5import javafx.stage.Stage; 6import javafx.scene.image.*; 7 8public class Sample extends Application{ 9 @FXML 10 ImageView imv; 11 12 @Override 13 public void start(Stage stage) throws Exception{ 14 Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); 15 Image img = new Image("file:one.jpg"); 16 imv = new ImageView(img); 17 imv.setImage(img); 18 19 Scene scene = new Scene(root); 20 stage.setTitle("first"); 21 stage.setScene(scene); 22 stage.show(); 23 } 24 25 public static void main(String[] args) { 26 launch(args); 27 } 28 29} 30
FXML
1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.image.ImageView?> 4<?import javafx.scene.layout.AnchorPane?> 5 6<AnchorPane id="AnchorPane" prefHeight="345.0" prefWidth="615.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="para.FXMLDocumentController"> 7 <children> 8 <ImageView id="imv" fitHeight="345.0" fitWidth="615.0" pickOnBounds="true" preserveRatio="true" /> 9 </children> 10</AnchorPane>
試したこと
SceneBuilder内のImageViewで、src内にある画像を参照したときは、表示されました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。