日期:2014-05-20 浏览次数:21089 次
JLabel labellogo = new JLabel();
ImageIcon imagelogo = new ImageIcon();
try {
imagelogo=ImageIO.read(getClass().getClassLoader().getResource("./images/Logo.jpg"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
labellogo.setIcon(imagelogo);
dialogPanel.add(labellogo,BorderLayout.EAST);
ImageIcon imagelogo = new ImageIcon();
BufferedImage imagelogo = null;
你参考一下
package test;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Test {
public Test() {
JFrame frame = new JFrame();
JLabel labellogo = new JLabel();
URL url = Test.class.getResource("images/1.PNG");;
System.out.println(url);
ImageIcon icon = new ImageIcon(url);
System.out.println(icon);
labellogo.setIcon(icon);
frame.add(labellogo, BorderLayout.EAST);
frame.setSize(300, 300);
frame.setVisible(true);
}
public static void main(String[] args) {
Test t = new Test();
}
}