【发布时间】:2018-07-26 00:50:51
【问题描述】:
我试图在 AnchorPane 中安装 ImageView,ImageView 是从数据库中获取的,所以没有 CSS,我尝试将 ImageView 的宽度和高度与 AnchorPane 的宽度和高度绑定,但我明白了结果:
这是我的 fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane style="-fx-background-color: grey;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="nombrePlato" alignment="CENTER" contentDisplay="CENTER" maxHeight="50.0" prefHeight="50.0" text="Nombre del Plato" textAlignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font size="30.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane fx:id="anchorPane" layoutY="300.0" styleClass="anchorPane" stylesheets="@../../../../core/resources/css/MainCSS.css" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="50.0">
<children>
<ImageView fx:id="imagenPlato" fitHeight="100.0" fitWidth="100.0" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>
</children>
</AnchorPane>
这是我的方法:
public void rellenar(Label nombrePlato, ImageView imagenPlato, Plato plato, AnchorPane anchorPane) throws SQLException {
nombrePlato.setText(plato.getNombre());
Blob blob = plato.getRutaImagen();
int blobLength = (int) blob.length();
byte[] blobAsBytes = blob.getBytes(1, blobLength);
Image convertToJavaFXImage = convertToJavaFXImage(blobAsBytes, 1024, 768);
imagenPlato.setImage(convertToJavaFXImage);
imagenPlato.fitWidthProperty().bind(anchorPane.widthProperty());
imagenPlato.fitHeightProperty().bind(anchorPane.heightProperty());
}
知道如何使它适合他的 anchorPane 并使其响应吗?
【问题讨论】:
标签: java javafx imageview pane