JTable CustomCellRenderer with JCustomTooltip

105 Views Asked by At

Riddle me this.

Take this simple MyCellRenderer example shown here...

class MyCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(
                    JTable table, Object value,
                    boolean isSelected, boolean hasFocus,
                    int row, int column) {
    JLabel c = (JLabel)super.getTableCellRendererComponent( // params from above );
    // This...
    c.setToolTipText("I don't want text, I want a custom JComponent here");
    return c;
}
}

but instead of simply accessing the super's rendered JLabel and adding a simple text toolTip, I want to override that JLabel and use a completely custom tooltip using the JCustomToolTip library http://prefuse.org/doc/api/prefuse/util/ui/JCustomTooltip.html

... but I want to maintain all the original properties of the super's rendered JLabel. The only thing that changes is the JCustomToolTip is added.

I have tried everything and nothing seems to work. I tried extending JLabel and overriding createToolTip(), and returning that child JLabel to the table (with all the properties copied from the super JLabel) ... but to no success. The JTable only seems to recognize text tooltips and Nimbus is not showing any of the original formatting.

What do I do?

1

There are 1 best solutions below

0
tmn On

If I get time I'll modify my code later for future reference to others. But I found the solution elsewhere on Stack Overflow. As I suspected, the JTable implements the JToolTip differently, as it is called on the JTable level, not the JComponent cell.

Overriding createToolTip() in a custom CellRenderer