Adding images on Java JFrame - Netbeans

老子叫甜甜 提交于 2019-12-19 10:52:00

问题


I'm using NetBeans 7.1 to code in Java. I have already created a JFrame filled with some labels, textbox and buttons. How can I do to import some image (JPG,PNG,etc...) from my PC into the same JFrame? On an specific location of the frame.


回答1:


  1. Open the form in NetBeans form editor.
  2. Add a JLabel from the pallete to the form
  3. Select the label you just added and click the "..." button next to the icon property
  4. Fill out the properties.

It's normally best that the images reside within the project folder, makes deployment easier in the long run.




回答2:


  1. Copy Image to your Netbeans project.
  2. Add new label to the frame.
  3. Select the label and Right click->Go to Properties.
  4. In Icon property select image by down arrow as shown in image.




回答3:


Make sure when you add the JLabel to use it from Swing Controls not AWT.



来源:https://stackoverflow.com/questions/15400371/adding-images-on-java-jframe-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!