List of utility methods to do String Align Center
String | alignCenter(String sLine, int iSize) align Center if (sLine.length() > iSize) { return alignRight(sLine.substring(0, (sLine.length() + iSize) / 2), iSize); } else { return alignRight(sLine + getWhiteString((iSize - sLine.length()) / 2), iSize); |
String | alignCenter(String str, int length) align Center return alignCenter(str, length, false);
|
String | alignCenter(String substring, int totalWidth, char fill) Returns a string of the specified length where the substring is located in the middle, padded with a character on both sides. if (substring.length() > totalWidth) { return substring.substring(0, totalWidth); } else { final double padding = (totalWidth - substring.length()) / 2d; final int left = (int) Math.floor(padding); final int right = (int) Math.ceil(padding); return repeat("" + fill, left) + substring + repeat("" + fill, right); |