Is it possible to use the methods that are in the rather important FontMetrics class without having a Graphics available? Is the nearest possible way of achieving this to create a headless-device and get a dummy Graphics from it?
Mostly, I’m interested in fixing the “feature” of various swing classes (like JTree) that practically ignore things like “setRowHeight”. However, there are so very very very many occasions when I need to fit text to an area that I’d like to make a generic class for it (I wish it were in the java.awt.* - if I’m missing something, please let me know! I’ve looked and looked and never found
).
Dynamic font-resizing can be extremely slow (especially on linux - big one-time penalty to get some font-cache somewhere filled) but you can get decent performance with standard tricks, like exponential “homing-in” on an approximately correct answer, erring on the side of being too small.
