Try this - it should scale the text to size of label
public int getMaxSize(Font f,
String text, double maxwidth, double maxheight, Graphics context) {
int size = f.getSize();
if (size == 0) size = 1;
boolean hasgotsmaller = false;
while (size > 0) { //might want to put a limit here in case something goes wrong e.g. while (size > 0 && size < 600) {
Font
test = f.deriveFont((float)size);
Rectangle2D bounds = context.getFontMetrics(test).getStringBounds(
text, context);
if (bounds.getWidth() > maxwidth || bounds.getHeight() > maxheight) {
size--;
hasgotsmaller = true;
} else if (hasgotsmaller){
break;
} else {
size++;
}
}
System.out.println(size);
return size;
}
Hope this helps you