Re: Automatically resize font when component size changes?
- From: bcd@xxxxxxxxxxx (Bent C Dalager)
- Date: Tue, 20 Mar 2007 15:10:40 +0000 (UTC)
In article <1174393441.687014.66540@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<larkmore@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. If I use that, I would have to:
1) Figure out which string is the widest and tallest of all possible
strings. I'm betting it's likely 88:88:88 but to be safe, I'd have to
check all of them for a given font. Some weird font might make
11:11:11 really wide.
If you draw the time as one single string (e.g. "12:34:56") as opposed
to drawing each single digit (and JLabel used in the straight-forward
manner would do the former) then you may also risk (weird) fonts
having compound glyphs (or whatever the technical term is) of pairs of
digits that are wider than twice the width of any one of the digits
involved.
E.g., the string "17" may draw wider than "11" _and_ wider than "77".
(Perhaps this is impossible - I don't know too much about font design
- but I wouldn't bet on it.)
To support this general case, you would have to measure the size of
all possible times from 00:00:00 to 23:59:59.
The alternative is to draw each digit separately. You then only have
to measure the size of each of the digits and you can position them as
you see fit to give the impression of them all staying in the same
place as the clock ticks along (which would also avoid any problems
you might otherwise get with proportional width fonts).
Cheers
Bent D
--
Bent Dalager - bcd@xxxxxxx - http://www.pvv.org/~bcd
powered by emacs
.
- Follow-Ups:
- Re: Automatically resize font when component size changes?
- From: John W. Kennedy
- Re: Automatically resize font when component size changes?
- From: Philipp
- Re: Automatically resize font when component size changes?
- References:
- Automatically resize font when component size changes?
- From: larkmore
- Re: Automatically resize font when component size changes?
- From: Andrew Thompson
- Re: Automatically resize font when component size changes?
- From: larkmore
- Automatically resize font when component size changes?
- Prev by Date: Re: Automatically resize font when component size changes?
- Next by Date: JFrame from JPanel
- Previous by thread: Re: Automatically resize font when component size changes?
- Next by thread: Re: Automatically resize font when component size changes?
- Index(es):
Relevant Pages
|