向JPanel中添加图片
来源:互联网 发布:网络推广教学视频 编辑:程序博客网 时间:2024/05/02 04:31
import java.awt.*;
import javax.swing.*;
public class PicDemo extends JFrame {
private JPanel main,p;
private Icon icon;
private JLabel l;
private PicDemo(){
main = new JPanel();
p = new JPanel();
l=new JLabel();
icon=new ImageIcon("C:\\Users\\Administrator\\Pictures\\cat.jpg"); //在此直接创建对象,注意目录之间的分隔符是双斜线
l.setIcon(icon);
l.setBounds(10, 10, icon.getIconWidth(),icon.getIconHeight());
p.add(l,new Integer(Integer.MIN_VALUE));
this.setVisible(true);
this.add(main);
main.add(p);
this.pack();
}
public static void main(String[] args) {
new PicDemo();
}
import javax.swing.*;
public class PicDemo extends JFrame {
private JPanel main,p;
private Icon icon;
private JLabel l;
private PicDemo(){
main = new JPanel();
p = new JPanel();
l=new JLabel();
icon=new ImageIcon("C:\\Users\\Administrator\\Pictures\\cat.jpg"); //在此直接创建对象,注意目录之间的分隔符是双斜线
l.setIcon(icon);
l.setBounds(10, 10, icon.getIconWidth(),icon.getIconHeight());
p.add(l,new Integer(Integer.MIN_VALUE));
this.setVisible(true);
this.add(main);
main.add(p);
this.pack();
}
public static void main(String[] args) {
new PicDemo();
}
}
组件由小到大分别添加次序:ImageIcon icon>JLabel l>JPanel p(p可以是最后一个面板,也可以将p再继续添加到其他面板中)
图片参数设置:setBounds(int x,int y,int width, int height)// x,y是组件左上角在容器中的坐标;width,height是组件的宽度和高度
0 0
- 向JPanel中添加图片
- java JPanel中添加一张图片的方法
- 向面板中添加图片
- 向AD中添加图片
- 向EditText中添加图片
- JPanel中添加一个新的JPanel,结果新的JPanel会自动占满父JPanel
- java中向Jscrollpane中加入Jpanel
- 向数据库中添加图片,显示图片
- JPanel中插入图片的方法
- ImagePanel 提供一个专门添加图片的JPanel
- VC中直接向水晶报表中添加图片
- 向RichEditCtrl中添加图片和URL功能
- 向图片中添加磁力链接与提取
- 使用POI向word中添加图片的问题
- 如何向Github README.md中添加图片,多人亲测,简单明了
- Java中为面板(JPanel)添加标题
- JScrollPane控件中添加JPanel后滚动条显示问题
- JFrame(框架)中添加和设置JPanel(面板)的方法
- iOS APP Store上线总结
- C/C++防止头文件重复包含的方法
- js去除小数点后面多余的零
- struts2 action详解
- Android Native/Tombstone Crash Log 详细分析
- 向JPanel中添加图片
- Debian 配置 (续)
- windows下WPS导致打开程序为未响应状态
- 2016老男孩Linux高薪运维28期
- 17.3.13 多任务学习 Multi-task learning
- Map
- 读书笔记-程序是如何跑起来的(第一章)
- leetcode解题之66 # Plus One Java版
- 通俗易懂的Map/Reduce原理