修改Swing组件JButton


把JButton修改成只在鼠标经过时才绘制边框,从而在按钮上创建悬浮效果

import javax.swing.JButton;
import java.awt.event.*;
public class JCoolButton extends JButton {
public JCoolButton() {
super();
init();
}

public void init() {
setBorderPainted(false);
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent arg0){
setBorderPainted(true);
}
public void mouseExited(MouseEvent arg0) {
setBorderPainted(false);
}
});
}
}

有鼠标经过时,无鼠标经过时

你可能感兴趣的:(swing)