-1

How can i enlarge a Jbutton from the center when it's hover? I use the method setSize(), but the button enlarges to the right and down. I'd like to make it enlarge to all the directions. The JButton is in a JPanel with a flowLayout. Thanks

1 Answers1

0

You should use a transparant border for your button, and when hovering over it, set the border-size to 0.

This is your initial code for the button border:

JButton btn = ...;
Color borderColor = new Color(0, 0, 0, 0,); //Transparant border
btn.setBorder(BorderFactory.createLineBorder(borderColor, 4));

When hover, you should set the border to this:

btn.setBorder(BorderFactory.createLineBorder(borderColor, 0));

That should be a quick workaround.

Titulum
  • 9,928
  • 11
  • 41
  • 79