java button添加图片不显示_JButton 图像按钮不能正常显示!

在Java中创建JButton时遇到图像无法显示的问题。代码尝试通过绝对路径加载图片,但未能成功。解决方案是将图片放入项目的一个包内,并使用相对路径加载,例如:`Icon I1 = new ImageIcon("com/StockMarket/GUI/Image/history.gif");`
摘要由CSDN通过智能技术生成

JButton 图像按钮不能正常显示!

import javax.swing.*;

import java.awt.*;

class ShowJButton extends JFrame

{

JButton jb1=new JButton ("up");

ImageIcon im1 =new ImageIcon("D:\\图片\\105");

JButton jb2=new JButton("down",im1);

ImageIcon im2=new ImageIcon("D:\\图片\\100");

JButton jb3 =new JButton(im2);

FlowLayout fl =new FlowLayout();

ShowJButton()

{

super("testing...");

setSize(200,150);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jb3.setToolTipText("out");

this.getContentPane().setLayout(fl);

this.getContentPane().add(jb1);

this.getContentPane().add(jb2);

this.getContentPane().add(jb3);

show();

}

public static void main(String[]args)

{

ShowJButton sjb=new ShowJButton();

}

}

按钮上图象都不能显示,求助!

搜索更多相关的解决方案:

JButton  图像  按钮

----------------解决方案--------------------------------------------------------

怎么能用绝对路径呢?做一个包放图片 比如:

Icon I1 = new ImageIcon("com/StockMarket/GUI/Image/history.gif");

----------------解决方案--------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值