Setting different sizes of text for buttons

Hi, I have a screen and I need 3 different sizes of text for the buttons.

Is the only way to do this to create 3 LAFs and apply the appropriate LAF to each button?


getTextButtonFont() gets a reference to the button… where it can get the text size for your TextButton derived Component.


Hi thx - yes, I was trying to find a solution without having to derive a new class, but looks like I need to do that. thx

The only other option I can think of for you otherwise is to use the TextButton text for the L&F getTextButtonFont() to know which button it is and you can have a switch for the text size… but it’s not a great (or elegant) solution.


Hi - agreed - already considered and junked that one :). I guess deriving a new class to add a size member isn’t that onerous…

The other option is using the getProperties() method of the Component class, you could set a property called fontSize and read it in your L&F?


hi, nice idea, thx!

1 Like