Код: Выделить всё
private Shape getShape(String text, Font font, FontRenderContext context, int max_width) {
TextLayout layout = new TextLayout(text, font, context);
double w = layout.getBounds().getWidth();
while (w>max_width) {
font = new Font(font.getFontName(), font.getStyle(), font.getSize()-1);
layout = new TextLayout(text, font, context);
w = layout.getBounds().getWidth();
}...