diff --git a/src/share/classes/javax/swing/text/Utilities.java b/src/share/classes/javax/swing/text/Utilities.java index e3ef4940d5a89a1951715cae259bc30d454a53c1..c9c066e1faaed9e766f0409bf293187d52bef13e 100644 --- a/src/share/classes/javax/swing/text/Utilities.java +++ b/src/share/classes/javax/swing/text/Utilities.java @@ -395,10 +395,10 @@ public class Utilities { // the length of the string measured as a whole may differ from // the sum of individual character lengths, for example if // fractional metrics are enabled; and we must guard from this. - while (metrics.charsWidth(txt, txtOffset, offset + 1) > (x - x0)) { + while (offset > 0 && metrics.charsWidth(txt, txtOffset, offset) > (x - x0)) { offset--; } - return (offset < 0 ? 0 : offset); + return offset; } currX = nextX; }