Jonah
Jonah

Reputation: 1003

Making jButton size not change when text changes

I currently have a jButton that when clicked it changes the background color and text of the button. I'm not gonna post all the code as there are many colors that it changes to. What I want is for the text to change but not change the size of the jButton based on the length of the string.

Upvotes: 0

Views: 519

Answers (1)

brso05
brso05

Reputation: 13232

Use a fixed size for the button. Whenever you change the text reset the size to your fixed size.

 btn.setPreferredSize(new Dimension(40, 40));

Try doing this...

btn.setMaximumSize()
btn.setMinimumSize()

Make them the same.

Upvotes: 1

Related Questions