通过FXML的JavaFX ImageView不起作用
发布时间:2020-05-25 00:31:35 所属栏目:Java 来源:互联网
导读:我在使用F XML上的ImageView加载图像时遇到问题. 我的控制器类: public class BoxViewController { @FXML private Label label_boxID; @FXML private ImageView boximage; public void initData(ObservableListBox
|
我在使用F XML上的ImageView加载图像时遇到问题. 我的控制器类: public class BoxViewController {
@FXML
private Label label_boxID;
@FXML
private ImageView boximage;
public void initData(ObservableList<BoxProperty> observableList,BoxService sBox,TableView tableview) {
this.label_boxID.setText(
String.valueOf(this.boxproperty.getPboxid()));
Image image = new Image("boximage.jpg");
this.boximage = new ImageView();
this.boximage.setImage(image);
}
}
因此,使用文本设置标签有效,但图像不会出现在我的ImageView中. <ImageView fx:id="boximage"
disable="false"
fitHeight="150.0" fitWidth="200.0"
layoutX="69.0" layoutY="322.0"
pickOnBounds="true"
preserveRatio="true" />
我很困惑,为什么这不起作用,因为标签工作,但图像不会加载. 解决方法也许这是源图像位置问题.根据 this website的评论,来自“Maxim”,如果你使用新的Image(“boximage.jpg”);,根目录是主项目文件夹,例如用于scene.getStylesheets().add(“login.css” );根文件夹是src.也许你可以试试这个: Image img = new Image("file:boximage.jpg");
ImageView imageView = new ImageView(img);
尝试将源图像移动到此代码的主项目文件夹 仅用于测试目的,尝试从FXML加载该图像: <ImageView id="boxImage" ...>
<image>
<Image url="@boximage.jpg" />
</image>
</ImageView> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
