JButton jb=new JButton();
jb.setIcon(new ImageIcon("image/1.jpg"));
是不是就这么两句话... 奇怪了.. 就是显示不出来 图片肯定没问题 后缀也为.jpg 路径也没错...
如果用getClass().getResource("image/1.gif"))... 这个值是null... 不明白什么意思 急啊!!!
jb.setIcon(new ImageIcon("image/1.jpg"));
是不是就这么两句话... 奇怪了.. 就是显示不出来 图片肯定没问题 后缀也为.jpg 路径也没错...
如果用getClass().getResource("image/1.gif"))... 这个值是null... 不明白什么意思 急啊!!!
我不知道把图片应该放在哪里!
点拨一下!
也可以放在其他任何地方,不过你必须写好路径,写路径时就按楼上说的
但是问题还是存在 图片依然是上不去JButton 但是运行后会在按钮中间会出现一个黑点.... 大概就一象素吧..... 没有用setIcon()的按钮没这黑点... 这是为什么 别人往上加图片好象没这么麻烦啊
还有就是我印象中有个图像填充的方法设置图像显示像素,你可以查下API文档
JButton jb=new JButton(new ImageIcon("image/1.gif")
就行了
已经实现了
JButton b;
Icon icon=new ImageIcon("images/1.gif");
b=new JButton(icon);
11楼说的我也试过 一样是一个点.....
大家帮忙看看这段程序在你们机器上运行有问题不
import java.awt.*;
import javax.swing.*;public class buttonicon extends JFrame
{private JButton jb = new JButton();
public buttonicon()
{
jb.setIcon(new ImageIcon(getClass().getResource("1.jpg")));
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(jb);
}
public static void main(String[] args)
{
buttonicon bi = new buttonicon();
bi.setSize(300, 300);
bi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bi.setVisible(true);
}
}
我重新安了
谢谢大家... 虽然只有20分.....