Automatically resize font when component size changes?
- From: larkmore@xxxxxxx
- Date: 19 Mar 2007 09:44:50 -0700
Is there a simple way to figure out what the biggest font size is that
can display a given text string on a given size component (JLabel,
etc.)?
I'm trying to write a widget that is essentially a digital clock, but
I want the user and/or other programs to be able to resize it as
needed. I'm extending it from a JLabel for simplicity. Trouble is,
JLabels do not change font size when their bounding size changes.
Other than a lot of calls to getFontMetrics(getFont()).charWidth('x')
is there an easy way to determine:
1) how big a string formatted as HH:MM:SS will render (maximum height
and width for any numeric combination)
2) how big an area the JLabel allows to be painted with text (I'm
guessing something to do with the Insets, but not sure)
3) the largest font size displaying the biggest HH:MM:SS string that
can be drawn onto the JLabel without clipping it into "..."
:(
-Will
.
- Follow-Ups:
- Re: Automatically resize font when component size changes?
- From: Andrew Thompson
- Re: Automatically resize font when component size changes?
- Prev by Date: Re: MacOS X: annoying rectangle during drag and drop
- Next by Date: Graphics transforms
- Previous by thread: New approuch in an accounting software
- Next by thread: Re: Automatically resize font when component size changes?
- Index(es):
Relevant Pages
|