0

可能重复:
如何向 JTable 的行添加工具提示

我想为给定特定列下的单元格上的用户鼠标悬停事件添加工具提示,以便单元格的值完全显示给用户。

4

2 回答 2

5

我认为覆盖 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;
    }
};
于 2012-10-29T13:46:14.440 回答
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;
    }

}
于 2012-10-29T19:17:10.690 回答