我想知道如何禁用JButton
鼠标光标悬停在 上时出现的发光效果。
user2328614
问问题
6462 次
2 回答
6
我认为您正在寻找:
button.setRolloverEnabled(false);
于 2013-04-30T15:21:49.850 回答
3
我想知道如何禁用当您将鼠标光标悬停在 JButton 上时出现的发光效果。
JButton.setFocusable(false);
编辑
MysticKiller 98 wrote that doesn't work,
然后发光效果等于JButton.setBorderPainted(false);
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class MyButtonWithIcon extends JFrame {
private static final long serialVersionUID = 1L;
private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon");
private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon");
public MyButtonWithIcon() {
final JButton toggleButton = new JButton();
toggleButton.setBorderPainted(false);
//toggleButton.setBorder(null);
//toggleButton.setFocusable(false);
//toggleButton.setMargin(new Insets(0, 0, 0, 0));
//toggleButton.setContentAreaFilled(false);
toggleButton.setIcon((errorIcon));
toggleButton.setSelectedIcon(infoIcon);
toggleButton.setRolloverIcon((infoIcon));
toggleButton.setPressedIcon(warnIcon);
toggleButton.setDisabledIcon(warnIcon);
add(toggleButton);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MyButtonWithIcon t = new MyButtonWithIcon();
}
});
}
}
于 2013-04-30T13:00:52.457 回答