关于JLabel无法加载图片的问题
以下为代码package Learn.Swing_GUI;
import java.awt.*;
import javax.swing.*;
public class Demo_jinshan extends JFrame{
//定义组件
JSplitPane jsp;
JList jlist;
JLabel jl1;
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo_jinshan demo6=new Demo_jinshan();
}
//构造函数
public Demo_jinshan(){
//创建组件
String []words= {"bird","long","package","hamberger","computer","pen","sock","quilt","bookcase"};
jlist=new JList(words);
jl1=new JLabel(new ImageIcon("./images/Icarus.png"));
//创建可拆分窗格
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
jsp.setOneTouchExpandable(true);
//设置布局管理器
//添加组件
this.add(jsp);
//设置窗体
int width=1280;
int height=720;
this.setTitle("词霸");
this.setSize(width, height);
this.setLocation((1920-width)/2, (1080-height)/2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//显示窗口
this.setVisible(true);
}
}
图片分辨率700*943 ImageIcon img = new ImageIcon(photoName);
ImageLabel = new JLabel(img);
getLayeredPane().add(ImageLabel, new Integer(Integer.MIN_VALUE));
ImageLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());
这是用JLabel加入图片要用到的代码
页:
[1]