Skip to content
Permalink
Browse files
8277504: Use String.stripTrailing instead of hand-crafted method in S…
…wingUtilities2

Reviewed-by: pbansal, serb
  • Loading branch information
turbanoff authored and mrserb committed Nov 26, 2021
1 parent 9879920 commit eb4d886bc0f57085b21ef41f2069ff60b2714cfa
Showing 1 changed file with 2 additions and 10 deletions.
@@ -520,7 +520,7 @@ public static void drawString(JComponent c, Graphics g, String text,
* 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 static float drawChars(JComponent c, Graphics g,
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 @@ static boolean isPrinting(Graphics g) {
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();

1 comment on commit eb4d886

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on eb4d886 Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.