code: public void removeTrailingWhitespaces()
      {
          int last = -1;
          for (int i = text.length() - 1; i >= 0; i--)
          {
              if (isWhitespace(text.charAt(i)))
                  last = i;
              else
                  break;
          }
          if (last != -1)
          {
              text = text.substring(0, last);
              textStart = 0;
              textEnd = last;
          }
      }
docs: Removes the trailing whitespaces from the cotnained text string. This must be done before the layout (it resets the text start and end pointers).