问题
Possible Duplicate:
How to add tooltips to JTable’s rows
I want to add tooltip for the user mouseover event on a cell under a given particular column so that the value of the cell completely displayed to the user.
回答1:
I think overriding prepareRenderer() may be easier for a single cell
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (c instanceof JComponent) {
if(column == X){
//X is your particlur column number
JComponent jc = (JComponent) c;
jc.setToolTipText(getValueAt(row, column).toString());
}
}
return c;
}
};
回答2:
Simply settle tooltip of you of the cell renderer
public class MyCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setToolTipText(...);
return this;
}
}
来源:https://stackoverflow.com/questions/13121575/how-to-add-tooltip-on-jtable-to-show-cell-values-of-a-particular-column-on-mouse