Netbeans ImageIcon没有显示 [英] Netbeans ImageIcon not displaying

查看:232
本文介绍了Netbeans ImageIcon没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetBeans GUIBuilder制作JPanel表单。我添加了一个JLabel并使用NetBeans的界面从外部图像(.png)给它一个图标。验证路径,图像显示在GUIBuilder屏幕上。当我点击预览设计按钮时,它甚至会显示出来。当我运行项目时它不会出现。 GUI的其余部分应该显示出来。你们有没有人知道为什么会发生这种情况和/或如何解决这个问题?

I am using the NetBeans GUIBuilder to make a JPanel Form. I added a JLabel and used NetBeans' interface to give it an icon from an external image (.png). The path is verified and the image shows up on the GUIBuilder screen. It even shows up when I click the "Preview Design" button. It DOES NOT show up when I RUN the project. The rest of the GUI appears as it should. Do any of you know why this happening and/or how to fix it?

很多人一直在要求SSCCE。由于代码是由NetBeans表单生成器生成的,因此我已经包含了制作JLabel所采取的步骤。焦点区域用红色圈出。

A lot of you have been asking for an SSCCE. Since the code is generated by the NetBeans Form Builder, I have instead included the steps I took to make the JLabel. The areas of focus are circled in red.


  1. 将JLabel拖放到表单生成器中。

  1. Drag and drop a JLabel into the Form Builder.

打开JLabel的属性菜单。输入 text 字段的空字符串()。单击图标旁边的省略号。

Open up the JLabel's properties menu. Enter the empty string ("") for the text field. Click the ellipsis next to icon.

选择外部图像并单击省略号。

Select External Image and click the ellipsis.

选择所需的图像。就我而言,它是一个.png。

Select the image of choice. In my case it's a .png.

请注意,图像显示在图标预览中。

Notice that the image appears in the icon preview.

关闭图标菜单和属性菜单,注意图像在表单生成器上显示为JLabel的图标。

Close the icon menu and the properties menu, and notice that the image appears as the JLabel's icon on the Form Builder.

感谢您接受非正统的SSCCE,并提前感谢您的帮助。

Thank you for accepting an unorthodox SSCCE and thank you in advance for your help.

推荐答案

我遇到了同样的问题,而且predi的解决方案也没有用。然后我创建了一个包而不是一个文件夹,并在那里添加了图像,现在它可以正常工作。

I had the same problem, and predi's solution wasn't working either. Then I created a package instead of a folder, and added the images there, and it works now.

这篇关于Netbeans ImageIcon没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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