首先说明,按钮没有icon属性,只有mouseicon和mousepointer属性,能让按钮显示图像的属性是picture属性(不过要想让按钮显示图片,要把按钮的Style属性在设计时先设为1,该属性运行时是只读的)Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Picture = LoadPicture("c:\windows\system\i81xcfg.ico")
End SubPrivate Sub Form_Load()
'要想按钮显示图片,要把按钮的Style属性先设为1
Command1.Picture = LoadPicture("c:\windows\winupd.ico")
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Picture = LoadPicture("c:\windows\winupd.ico")
End Sub
Command1.Picture = LoadPicture("c:\windows\system\i81xcfg.ico")
End SubPrivate Sub Form_Load()
'要想按钮显示图片,要把按钮的Style属性先设为1
Command1.Picture = LoadPicture("c:\windows\winupd.ico")
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Picture = LoadPicture("c:\windows\winupd.ico")
End Sub
你看这些
button.setPressedIcon(createImageIcon("*.gif");
button.setRolloverIcon(createImageIcon("*.gif");
button.setDisabledIcon(createImageIcon("*.gif");
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setMargin(new Insets(0,0,0,0));
你不会看不懂这吧??? *.gif 表示表示 三张图片 就是 显一张
鼠标在按钮上的时候 一张 鼠标按下去后又显示一张 不懂就[email protected]
import java.awt.*;
import java.awt.event.*;
import java.net.*;public class TestChangedIcon extends JApplet implements ActionListener
{
JButton testjb;
public void init()
{
Container c=getContentPane();
Icon normalIcon=new ImageIcon("g1.gif");
Icon pressedIcon=new ImageIcon("g2.gif");
Icon rolloverIcon=new ImageIcon("g3.gif");
testjb=new JButton(normalIcon);
testjb.setPressedIcon(pressedIcon);
testjb.setRolloverIcon(rolloverIcon);
testjb.setRolloverEnabled(true);
c.add(testjb,BorderLayout.NORTH);
testjb.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
showStatus("响应单击J按钮");
}
}这是一个applet小程序,需要加载到html文件里,这个应该会吧!g1,g2,g3为你想用的图片!
你用jbuilder,在事件中添加对鼠标操作的几个函数,
如上: dut_ice() 所讲的:
testjb.setPressedIcon(pressedIcon);
testjb.setRolloverIcon(rolloverIcon);
就可以了。不骗你真的很容易实现的。
举个例子:
在同目录下有一个图片:beauty.jpg,
jLabel.setIcon(new ImageIcon(".//beauty.jpg"));
或
jButton.setIcon(new ImageIcon(".//beauty.jpg"));
就搞定了!!!