如何插入jar文件的调色板组件?
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
/**
* Created with IntelliJ IDEA.
* User: user
* Date: 05.07.13
* Time: 17:51
* To change this template use File | Settings | File Templates.
*/
public class ImageViewerBean extends JLabel {
private File file=null;
int XPREFSIZE=200;
int YPREFSIZE=200;
public ImageViewerBean(){
setBorder(BorderFactory.createEtchedBorder());
}
public void setFileName(String fileName)
{
File file1=new File(fileName);
try {
setIcon(new ImageIcon(ImageIO.read(file)));
} catch (IOException e) {
file=null;
setIcon(null);
}
}
public String getFileName(){
if (file!=null)
return file.getPath();
else
return null;
}
public Dimension getPreferredSize(){
return new Dimension(XPREFSIZE,YPREFSIZE);
}
}
显现:
清单版本:1.0
名称:C:\Users\user\IdeaProjects\AWTLearn\src\ImageViewerBean.java Java-Bean:真
在宣言中,所有空字符串的末尾都严格没有多余的空格。