在netbeans中执行时,在场景构建器中导入的图像不会显示 [英] Images imported in scene builder is not getting displayed while executed in netbeans

查看:137
本文介绍了在netbeans中执行时,在场景构建器中导入的图像不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了此图像显示外,所有功能都正常工作。但在场景构建器预览中它的工作正常。有人可以帮忙吗?

All the functionalities are working fine except this image display. But in Scene builder preview its working fine. Can someone help in this??

推荐答案

也许你链接了项目目录之外的图片,我做了一个小而简单的例子,效果非常好。

maybe you linked images from outside the projectdirectory, i made a small and simple example, which works quite well.

将图像放入同一个包中,放置fxml文件并在Scene Builder中将其再次链接到新位置。

Put your image into the same package, where you placed your fxml file and link it again in Scene Builder to the new location.

这是一个小代码:
App.java

Here's a little code: App.java

package com.example.images;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class App extends Application{

    @Override
    public void start(Stage stage) throws Exception {
        Parent parent = FXMLLoader.load(getClass().getResource("images.fxml"));
        stage.setTitle("Image set in Scene Builder");
        Scene scene = new Scene(parent);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

和fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" fx:id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="com.example.images.controller.MainController">
  <children>
    <ImageView fitHeight="337.875" fitWidth="540.6" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
      <effect>
        <Lighting surfaceScale="5.0">
          <bumpInput>
            <Shadow />
          </bumpInput>
          <light>
            <javafx.scene.effect.Light.Distant azimuth="-135.0" />
          </light>
        </Lighting>
      </effect>
      <image>
        <Image url="@1.png" backgroundLoading="true" />
      </image>
    </ImageView>
  </children>
</AnchorPane>

Patrick

这篇关于在netbeans中执行时,在场景构建器中导入的图像不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆