Re: Automatically resize font when component size changes?



On Mar 20, 11:24 pm, larkm...@xxxxxxx wrote:
Thanks Andrew, but I kind of hoping there would be something a little
simpler. I've already looked at the FontMetrics as described in my
first post.

Huhh.. I missed that important detail.

..If I use that, I would have to:

(snip process)
...only glanced at it, but it sounds about right.

What I'm looking for is a way to drastically speed up this process so
I have the user resize the control on the fly without tanking the CPU.

I suspect that any method of determining
the text size, would ultimately come back
to calling those same FontMetrics methods.

This almost smacks of 'premature optimisation'.
Try it, and see if the CPU does bog down. I'll
almost bet it has no appreciable effect, if the
methods are only called when required (e.g.
display size changing*).

The only other thing I can think of to mention,
is that perhaps a JLabel is too complex a
component to be using for this particular use.
I would be tempted to simply use a JPanel and
override paintComponent() directly.

* As as aside, why and when does the diplay
size change? Is it based upon the user
dragging the display bigger/smaller, or
is it more like a menu item that offers
a small number of preset sizes?
Something else?

Andrew T.

.