我想在Java中使用图像作为按钮,并尝试这样做:
BufferedImage buttonIcon = ImageIO.read(new File("buttonIconPath"));
button = new JButton(new ImageIcon(buttonIcon));
但这仍然显示了图像后面的实际按钮,我只想让图像起到按钮的作用,我该怎么做?
发布于 2011-02-04 21:42:52
建议将Image设置为标签,并在标签中添加鼠标侦听器以检测点击。
示例:
ImageIcon icon = ...;
JLabel button = new JLabel(icon);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
... handle the click ...
}
});
发布于 2011-02-04 22:12:46
ButtonIcon.setBorder(新EmptyBorder(0,0,0,0));
发布于 2011-02-04 23:38:28
button.setBorderPainted( false );
https://stackoverflow.com/questions/4898584
复制相似问题