
Toolkit tk = Toolkit.getDefaultToolkit()
private Image bground = tk.createImage("D://workpalce//MarketManagement//src//images//bgd2.gif")
protected void paintComponent(Graphics g) {
g.drawImage(bground, 0, 0, this.getWidth(), this.getHeight(), this)
}
1)文件要有后缀名2)要用Image或BufferedImage对象
3)因为你重写了paint()方法,所以不能在Label里面显示图片。你重写了paint()方法后,整个容器都会变成画布,所以看不到Label组件,自然也就看不到图片。应该在paint方法里面用g.drawImage方法把图片在画布中画出来。参考Java API,Graphics的drawImage方法。
那你要在控件所在的面板中插入这张图片当背景:public void paint(Graphics g) {
g.drawImage(IMAGE_BG, 0, 0, this)
super.paint(g)
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)