各位高手帮帮忙,java新手,请问如何在java面板中显示一张图片?
------解决方案--------------------
在 jbInit() 里加入如下代码
Toolkit toolImg = this.getToolkit();
Image myimage = toolImg.getImage( "image/pic.png ");//图片路径相对与工程图片文件夹下的图片路径
this.setIconImage(myimage);
------解决方案--------------------
package com.shlq.sample;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ImagePane extends JPanel
{
JLabel jl = null;
ImageIcon img = null;
public ImagePane()
{
img = new ImageIcon( "E:\\Picture\\1.jpg ");
jl = new JLabel(img);
this.setLayout(new BorderLayout());
this.add(jl, BorderLayout.CENTER);
}
public static void main(String[] args)
{
JFrame test = new JFrame( "Image Pane ");
test.getContentPane().add(new ImagePane());
test.pack();
test.setVisible(true);
test.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
------解决方案--------------------
new ImageIcon(getClass().getResource( "/userInterface/res/logo.gif "))