Why are font sizes for TextButton / Combo box set in L&F?


Hi all,

I’m about to embark on resizing for my next plugin GUI. Most of the elements I use should be able to be recalculated on the fly with my resizing code, with font sizes shrinking proportionately. However, the ComboBox and TextButton have their font sizes & styles set from the Look and Feel, and as far as I know, the Look and Feel can’t be modified on the fly. So, what is the best solution here? And why can’t we set font sizes / styles outside of the L&F for ComboBox and TextButton?


Sean Costello

Setting TextButton font size

The L+F can use whatever font size you want it to - all the relevant methods that create or use a font should get a reference to the button, so it can calculate the appropriate size for that button on the fly.


Can you show a quick example of how to change the font size of a TextButton on the fly?




There’s a getFontForTextButton method - just overload it to return whatever size you want for that button.


I guess a better question should have been, how do you pass the new size into the look and feel, so it can recalculate things on the fly?

Right now, my GUI has resizable sliders, knobs, labels, and text buttons. The things that still need to be resized: the fonts used in slider labels and combo boxes. How would you pass the new size to the L&F?


Sean Costello


You don’t pass the size to the L+F. The L+F should do whatever is appropriate for each component… E.g. getFontForTextButton is given a button parameter, so it can look at the size of that button, or ask it questions, and figure out the correct font to return.


OK, I’ve figured out some solutions in the L&F for resizing the fonts for all the controls I am currently using, except for the Slider text boxes. Two questions:

  • How would I adjust the Slider text boxes? (I’ve asked this in another post, so answering in either is fine)

  • And, back to the title of the thread: Why are the font sizes only set in the L&F for some controls? It would be far easier to set the font for the ComboBox/TextButton/Slider/etc. via setFont(), versus the L&F method.

The modifications seem easy to allow font size, styles, etc., to be set directly. Just change the declaration of the Label class in question to protected (instead of private), and create a setFont() method that calls the setFont() of the Label class. Any good reason not to do this?

Sean Costello


Not if you’re trying to change the look of ALL these components in your whole program, including ones that are created internally by the library and which you don’t have access to.

If you need a really custom kind of component, you can always subclass one of these and make it do anything you want, e.g. ignore the l+f completely and use whatever font you give it.