I'm trying to insert an image inside a HBox
through a ImageView
but I'm not getting it.
fxml code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="borderPane" stylesheets="@../css/botoes.css" id="BorderPane" xmlns:fx="http://javafx.com/fxml/1" fx:controller="teste.FXMLDocumentController">
<left>
<HBox fx:id="hbox" alignment="CENTER">
<Button fx:id="btnIniciar" onAction="#acaoIniciar" />
<Button fx:id="btnPausar" onAction="#acaoPausar" />
<Button fx:id="btnParar" onAction="#acaoParar" />
<Button fx:id="btnSubirFila" onAction="#acaoSubirFila" />
<Button fx:id="btnDescerFila" onAction="#acaoDescerFila" />
<Button fx:id="btnRemover" onAction="#acaoRemover" />
<Button fx:id="btnAdicionarArquivo" onAction="#acaoAdicionarArquivo" />
<Button fx:id="btnLinkMagnetico" onAction="#acaoLinkMagnetico" />
<Button fx:id="btnGerarTorrent" onAction="#acaoGerarTorrent" />
</HBox>
</left>
<right>
<HBox fx:id="hbox2" alignment="CENTER">
<ImageView fx:id="image" disable="false" fitHeight="60" fitWidth="60" pickOnBounds="true" preserveRatio="true" />
<TextField fx:id="txtPesquisar" />
</HBox>
</right>
</BorderPane>
To test, I removed the line where I inserted the ImageView
into fxml and added the image through the controller in the following snippet:
this.image = new ImageView(new Image("/imagens/iniciar.png"));
this.image.setFitHeight(TAMANHO_IMAGEM_X);
this.image.setFitWidth(TAMANHO_IMAGEM_Y);
this.hbox2.getChildren().add(image);
And miraculously no error occurred!
I also tried to insert the image inside the ImageView
into the fxml file, without creating any object in the controller:
<ImageView fx:id="image" disable="false" fitHeight="60" fitWidth="60" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../imagens/iniciar.png" />
</image>
</ImageView>
But it did not work either.
Detail: in this last test appeared, among several others, the following line in the output:
Caused by: javafx.fxml.LoadException: ImageView is not a valid type.
My biggest problems with javaFX are like this, I try to use fxml and a controller and it starts to pop up errors.