My hack's been pretty manual, scaling the font size down based
on the character length of the label beyond a hand-estimated
'maximum chars that should fit'. :) As with yours, I only did it on
one or two high-priority labels.
A proper implementation should be using font metrics by asking
the system how big that chunk of text would be rendered at a given
font size, then keep bumping the size down until it fits in the
available space. That could possibly be done by bumping around the
size of a transparent or hidden label, but that's probably slower
and nastier than having the Java-side code do it.