java 按钮图片 不显示(路径没错 格式也没错)

来源:百度知道 编辑:UC知道 时间:2024/06/05 09:40:46
private JButton buttonWithTitle=new JButton("Button with Title",new ImageIcon("java.jpg"));
这个是 按钮的 那条语句,但是 只能显示文字不显示图片 图片格式换成 gif的也不行
附上一张图片,里边是我保存文件的路径,不知道对不对(只是个例子 和上边说的不是一个 图片文件)

private JButton buttonWithTitle=new JButton("Button with Title",new ImageIcon("src/anwendung/tree.jpg"));
你要指定从哪去找才可以,虽然NetBeans和Eclipse都有自己的工作区间!!!

这样试试:
private JButton buttonWithTitle=new JButton("Button with Title");
buttonWithTitle.setImageIcon(new ImageIcon("java.jpg"));