int (Object component, int x, int y, boolean hidden) { String text = getString(component, "text", ""); FontMetrics fm = getFontMetrics(getFont()); for (int i = 0, j = 0; true; i = j + 1) { j = text.indexOf('\n', i); if ((j == -1) || y < fm.getHeight()) { if (j == -1) { j = text.length(); } for (int k = i; k < j; k++) { int charwidth = fm.charWidth(hidden ? '*' : text.charAt(k)); if (x <= (charwidth / 2)) { return k; } x -= charwidth; } return j; } y -= fm.getHeight(); } }