96 | | AttributedString as = new AttributedString(getText()); |

97 | | as.addAttribute(TextAttribute.FONT, getFont()); |

98 | | AttributedCharacterIterator aci = as.getIterator(); |

99 | | LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); |

100 | | float max = 0; |

101 | | while (lbm.getPosition() < aci.getEndIndex()) { |

102 | | TextLayout textLayout = lbm.nextLayout(width); |

103 | | if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) |

104 | | textLayout = textLayout.getJustifiedLayout(width); |

105 | | if (g != null) |

106 | | textLayout.draw(g, x, y + textLayout.getAscent()); |

107 | | y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); |

108 | | max = Math.max(max, textLayout.getVisibleAdvance()); |

| 98 | String[] lines = getText().split("\n"); |

| 99 | for(String line : lines) { |

| 100 | // Insert a space so new lines get rendered |

| 101 | if(line.length() == 0) line = " "; |

| 102 | AttributedString as = new AttributedString(line); |

| 103 | as.addAttribute(TextAttribute.FONT, getFont()); |

| 104 | AttributedCharacterIterator aci = as.getIterator(); |

| 105 | LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); |

| 106 | float max = 0; |

| 107 | while (lbm.getPosition() < aci.getEndIndex()) { |

| 108 | TextLayout textLayout = lbm.nextLayout(width); |

| 109 | if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) |

| 110 | textLayout = textLayout.getJustifiedLayout(width); |

| 111 | if (g != null) |

| 112 | textLayout.draw(g, x, y + textLayout.getAscent()); |

| 113 | y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); |

| 114 | max = Math.max(max, textLayout.getVisibleAdvance()); |

| 115 | } |

| 116 | w += max; |