当前位置:编程学习 > JAVA >>

各位大神求解,今天在做JBUTTON时候遇到个问题

是这样的我今天写了一个类继承了jbutton,重写了jbutton的paintComponent方法,我在这个方法里面没写任何代码,然后我把这个放到了一个jpanel上面,为什么这个重写后的jbutton里面还有一个框呢,要怎么去掉呢

我的重写的代码是这样的
public class MyFrame extends JFrame{
private static final long serialVersionUID = 1L;
private JButton imgButton;

public MyFrame() 
{
super();
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(null);
this.setContentPane(panel);
this.setBounds(100, 100, 300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//imgButton = new MyImageButton(new ImageIcon("im/1.jpg").getImage());
imgButton  = new m();
imgButton.setBounds(27, 26, 90, 90);
panel.add(imgButton);
}

public static void main(String[] args) {
new MyFrame().setVisible(true);
}

class m extends JButton
{
@Override
protected void paintComponent(Graphics g) {

}
}

} --------------------编程问答--------------------
我运行了你的代码,但是没有你说的框。。。。我是XP系统 --------------------编程问答-------------------- 难道是系统问题吗,我的是w7系统 --------------------编程问答-------------------- 我现在改用jlabel了 --------------------编程问答--------------------
引用 2 楼 Java2724 的回复:
难道是系统问题吗,我的是w7系统

肯定跟系统没关系,倒是有可能跟jdk版本有关,我是1.7,没问题
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,