8277504: Use String.stripTrailing instead of hand-crafted method in SwingUtilities2
Reviewed-by: pbansal, serb
This commit is contained in:
parent
9879920424
commit
eb4d886bc0
@ -520,7 +520,7 @@ public class SwingUtilities2 {
|
||||
* it to fit in the screen width. This distributes the spacing
|
||||
* more evenly than directly laying out to the screen advances.
|
||||
*/
|
||||
String trimmedText = trimTrailingSpaces(text);
|
||||
String trimmedText = text.stripTrailing();
|
||||
if (!trimmedText.isEmpty()) {
|
||||
float screenWidth = (float) g2d.getFont().getStringBounds
|
||||
(trimmedText, getFontRenderContext(c)).getWidth();
|
||||
@ -866,7 +866,7 @@ public class SwingUtilities2 {
|
||||
String text = new String(data, offset, length);
|
||||
TextLayout layout = new TextLayout(text, g2d.getFont(),
|
||||
deviceFontRenderContext);
|
||||
String trimmedText = trimTrailingSpaces(text);
|
||||
String trimmedText = text.stripTrailing();
|
||||
if (!trimmedText.isEmpty()) {
|
||||
float screenWidth = (float)g2d.getFont().
|
||||
getStringBounds(trimmedText, frc).getWidth();
|
||||
@ -1321,14 +1321,6 @@ public class SwingUtilities2 {
|
||||
return (g instanceof PrinterGraphics || g instanceof PrintGraphics);
|
||||
}
|
||||
|
||||
private static String trimTrailingSpaces(String s) {
|
||||
int i = s.length() - 1;
|
||||
while(i >= 0 && Character.isWhitespace(s.charAt(i))) {
|
||||
i--;
|
||||
}
|
||||
return s.substring(0, i + 1);
|
||||
}
|
||||
|
||||
private static AttributedCharacterIterator getTrimmedTrailingSpacesIterator
|
||||
(AttributedCharacterIterator iterator) {
|
||||
int curIdx = iterator.getIndex();
|
||||
|
Loading…
x
Reference in New Issue
Block a user