This is my final code, including making sure the line ends on a space, incase you were woundering. Thanks again
new javax.swing.JTable()
{
public String getToolTipText(java.awt.event.MouseEvent e) {
String tip = null;
java.awt.Point p = e.getPoint();
int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
int realColumnIndex = convertColumnIndexToModel(colIndex);
if (realColumnIndex == 3) { // comment column
tip = (String) getValueAt(rowIndex, colIndex);
}
int numberOfLines = 0;
String newTip = "<html><body>";
//If tip is greater than 50 chars add a new line else leave on one line
if (tip.length() > 50) {
numberOfLines = (int) (tip.length() / 50);
//numberOfLines will most likely not be a whole number so add 1 just in case
numberOfLines += 1;
for (int i = 0; i < numberOfLines; i++) {
if (tip.length() > 50) {
//Find the space in the line. Do this so the word is not spilt on two lines
int indexOfSpace = 50;
while(indexOfSpace < tip.length() && tip.charAt(indexOfSpace) != ' '){
indexOfSpace++;
}
//tip is greater then 50 add a new line. Also change tip to start at indexOfSpace
newTip += "<p>"+tip.substring(0, indexOfSpace) + " </p>";
tip = tip.substring(indexOfSpace, tip.length());
} else {
//the remaining tip is not 50 chars long just add the remainder to new tip
newTip += "<p>"+tip.substring(0, tip.length()) + "</p>";
}
//Add closing tags
newTip += "</body></html>";
}
} else {
//tip was less than 50 chars leave on one line
newTip = tip;
}
return newTip;
}
}