I think you're looking for something like this:
packagebr;importjava.awt.AlphaComposite;importjava.awt.Color;importjava.awt.FlowLayout;importjavax.swing.*;importjavax.swing.JButton;importjavax.swing.JFrame;publicclassCriarJButtonextendsJFrame{privatestaticfinallongserialVersionUID=1L;publicCriarJButton(){this.getContentPane().setLayout(newFlowLayout());finalbotaoFadebt=newbotaoFade("StackOverflow.pt");
bt.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
bt.setAlpha((float)0.6);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
bt.setAlpha((float)1);
}
});
add(bt);
}
private static void cria_MostraInterface() {
JFrame painel = new CriarJButton();
painel.pack();
painel.setVisible(true);
painel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
cria_MostraInterface();
}
});
}
private static class botaoFade extends JButton {
private static final JButton lafDeterminer = new JButton();
private static final long serialVersionUID = 1L;
private boolean rectangularLAF;
private float alpha = 1f;
botaoFade() {
this(null, null);
}
botaoFade(String texto) {
this(texto, null);
}
botaoFade(String texto, Icon icon) {
super(texto, icon);
setOpaque(false);
setFocusPainted(false);
}
public float getAlpha() {
return alpha;
}
public void setAlpha(float alpha) {
this.alpha = alpha;
repaint();
}
@Override
public void paintComponent(java.awt.Graphics g) {
java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
if (rectangularLAF && isBackgroundSet()) {
Color c = getBackground();
g2.setColor(c);
g.fillRect(0, 0, getWidth(), getHeight());
}
super.paintComponent(g2);
}
@Override
public void updateUI() {
super.updateUI();
lafDeterminer.updateUI();
rectangularLAF = lafDeterminer.isOpaque();
}
}
}
I have chosen to modify the whole button, but if you want to apply only on the border, it will not be that difficult.
If you want, you can download the code at gist .