how can I implement a tooltip which shows me for each cell a tip when the value is too long?
I just have a table renderer which colors me some cell. So I think the easiest way is to implement the metod in it.
public class ColorRenderer extends DefaultTableCellRenderer {
final int STATUS_COL = 7;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
hasFocus,
int row, int col) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
int modelIndex = table.convertRowIndexToModel(row);
String type = (String) table.getModel().getValueAt(modelIndex, 7);
if ("".endsWith(type)) {
component.setBackground(table.getBackground());
component.setForeground(table.getForeground());
} else {
component.setBackground(Color.RED);
component.setForeground(Color.WHITE);
}
if (isSelected) {
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
}
return component;
}
}
Thank you in advance.
Start by overriding the
getToolTipText(MouseEvent)
event of theJTable
.Get the cell coordinates for the given mouse location...
Get the cells current size, this way we know what the current constraints are...
Get the renderer for the cell, based on the current value for the cell from the model...
Compare the preferred size of the renderer component against the cell size...
Return the tool tip...