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
Asked
Active
Viewed 43 times
1 Answers
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
-
Very smart solution, really simple. Tanks – Alessandro Bonadei Feb 03 '17 at 14:29
-
Could you mark my answer as the correct one? Here is how to do it: https://stackoverflow.com/help/accepted-answer – Titulum Feb 03 '17 at 15:17