FontMetrics fm = g.getFontMetrics(); Rectangle2D bounds = fm.getStringBounds(s, g);  String[] ss = s.split("\n");  ArrayList lines = new ArrayList(ss.length);  for (int i = 0; i < ss.length; i++) { int linebreak = ss[i].length() - 1; while (linebreak != -1 && fm.getStringBounds(ss[i].substring(0, linebreak), g).getWidth() > wrapWidth) { linebreak = ss[i].lastIndexOf(' ', linebreak - 1); }  if (linebreak != -1 && linebreak != ss[i].length() - 1) { lines.add(ss[i].substring(0, linebreak)); ss[i] = ss[i].substring(linebreak + 1); i--; } else { lines.add(ss[i]); } }  ss = (String[]) lines.toArray(new String[lines.size()]);  int x; int y;  int height = (int) bounds.getHeight() * ss.length; switch (position / 10) { case 1: default: y = textY; break;  case 2: y = textY - height / 2; break;  case 3: y = textY - height; break; }  y += fm.getAscent();  for (int i = 0; i < ss.length; i++) { Rectangle2D bounds1 = fm.getStringBounds(ss[i], g); switch (position % 10) { case 2: default: x = textX; break;  case 0: x = textX - (int) bounds1.getWidth() / 2; break;  case 4: x = textX - (int) bounds1.getWidth(); break; }  paintOutline(g, ss[i], x, y, thickness);  y += bounds.getHeight(); }
paintAlignedOutline(g, s, textX, textY, thickness, position, wrapWidth, wrap((Graphics2D) g, s, wrapWidth), false);
	public static void paintAlignedOutline(			Graphics g,			String s,			int textX, int textY,			int thickness,			int position,			int wrapWidth) {		FontMetrics fm = g.getFontMetrics();		Rectangle2D bounds = fm.getStringBounds(s, g);		String[] ss = s.split("\n");		ArrayList lines = new ArrayList(ss.length);		for (int i = 0; i < ss.length; i++) {			int linebreak = ss[i].length() - 1;			while (linebreak != -1 && fm.getStringBounds(ss[i].substring(0, linebreak), g).getWidth() > wrapWidth) {				linebreak = ss[i].lastIndexOf(' ', linebreak - 1);			}			if (linebreak != -1 && linebreak != ss[i].length() - 1) {				lines.add(ss[i].substring(0, linebreak));				ss[i] = ss[i].substring(linebreak + 1);				i--;			} else {				lines.add(ss[i]);			}		}		ss = (String[]) lines.toArray(new String[lines.size()]);		int x;		int y;		int height = (int) bounds.getHeight() * ss.length;		switch (position / 10) {			case 1:			default:				y = textY;				break;			case 2:				y = textY - height / 2;				break;			case 3:				y = textY - height;				break;		}		y += fm.getAscent();		for (int i = 0; i < ss.length; i++) {			Rectangle2D bounds1 = fm.getStringBounds(ss[i], g);			switch (position % 10) {				case 2:				default:					x = textX;					break;				case 0:					x = textX - (int) bounds1.getWidth() / 2;					break;				case 4:					x = textX - (int) bounds1.getWidth();					break;			}			paintOutline(g, ss[i], x, y, thickness);			y += bounds.getHeight();		}	}