开发者

how to put Image on JPanel using Netbeans

And how do I put Ima开发者_StackOverflow中文版ge on a JPanel using Netbeans?


Have a look at this tutorial: Handling Images in a Java GUI Application

At the same time you could code as well:

JPanel panel = new JPanel(); 
ImageIcon icon = new ImageIcon("image.jpg"); 
JLabel label = new JLabel(); 
label.setIcon(icon); 
panel.add(label); 


You can use ImageIcon and JLabel:

ImageIcon icon = createImageIcon("image.gif", "sample image");

// Label with text and icon
JLabel label1 = new JLabel("Image and Text", icon, JLabel.CENTER);

// Label with icon only
JLabel label2 = new JLabel(icon);

// Add to your JPanel
panel.add(label1);
panel.add(label2);


1) First Paste the image to the Application folder 2) Add a label to the panel 3) Right click label-> Properties 4) Select Icon-> more option 5) Select Package and File and Click oK 6) U R DONE :)


You have to set a JLabel with your icon property set to the picture. For a more detailed solution to the particular problem, go to

http://www.netbeanstutorials.com/p/handling-images.html

There's even a video how to do it there in case you need it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜