java - How do I set the font size of the text on a swing jButton to the maximum size who fits the jButton -


i've got jpanel jbutton, , user can define size of jpanel when launching application using parameters, jbutton sizes according jpanel.

the problem when use fixed font , panel large, font looks small, , vica versa.

so font size should maximum font size fits in button.

not sure, might find size using graphics.getfontmetrics() method inside paintcomponent-method? maybe can use fontmetrics.getstringbounds() methods , test if button contains rectangle (rectangularshape.contains()).

you use binary search algorithm find max font.

make sure take insets account.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -