问题
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:
- Open the form in NetBeans form editor.
- Add a
JLabelfrom the pallete to the form - Select the label you just added and click the "..." button next to the
iconproperty - Fill out the properties.
It's normally best that the images reside within the project folder, makes deployment easier in the long run.
回答2:
- Copy Image to your Netbeans project.
- Add new label to the frame.
- Select the label and Right click->Go to Properties.
- 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