我想在给定特定列下的单元格上为用户鼠标悬停事件添加工具提示,以便将单元格的值完全显示给用户。
答案 0 :(得分:4)
我认为覆盖prepareRenderer()对于单个单元格来说可能更容易
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;
}
};
答案 1 :(得分:0)
只需解决单元格渲染器的工具提示
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;
}
}