Automatically resize font when component size changes?



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

.



Relevant Pages

  • Re: Layout Problem!
    ... JPanel panel = new JPanel; ... JButton buttonStart; ... String serverName; ... JLabel labelServername; ...
    (comp.lang.java.help)
  • Re: add a String to a JScrollPane
    ... > I have a String which is changing and I want to display it in a JScrollPane. ... With a JLabel you can change the text at any time you want. ... JScrollPane, to cause it to ask the JLabel about its next size. ...
    (comp.lang.java.help)
  • Re: Japanese character encoding
    ... characters. ... When I add these to e.g. a JLabel they show up fine, ... checked the string in a debugger and it shows the Unicode values in the ... whatever) doesn't support unicode? ...
    (comp.lang.java.programmer)
  • Japanese character encoding
    ... I´m writing a program where I read a file which contains some japanese ... characters. ... When I add these to e.g. a JLabel they show up fine, ... checked the string in a debugger and it shows the Unicode values in the ...
    (comp.lang.java.programmer)
  • Re: Automatically resize font when component size changes?
    ... can display a given text string on a given size component (JLabel, ... Andrew T. ...
    (comp.lang.java.gui)