为JTable添加单元格工具提示

覆盖JTable的getToolTipText(MouseEvent e)方法

 

@Override
public String getToolTipText(MouseEvent e) {
	int col = columnAtPoint(e.getPoint());
	if (col != 0) {
		return null;
	}
	int row = rowAtPoint(e.getPoint());
	String toolTip = null;
	if (row > -1 && col > -1) {
		Object value = getValueAt(row, col);
		if (value != null && !value.toString().isEmpty())
			toolTip = value.toString();
	}
	return toolTip;
}
 

 

你可能感兴趣的:(jtable)