I have a JTable
. One column holds a JPanel
which contains some JLabels
with ImageIcons
. I have created a custom cell render and all works fine apart from the tool tip on the JLabel
. When I mouse over any of these JLabels
I need to show the Tooltip
of that particular JLabel
. Its not showing the tootlip of the JLabel
.
Here is the CustomRenderer
.
private class CustomRenderer extends
DefaultTableCellRenderer implements TableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (value != null && value instanceof List) {
JPanel iconsPanel = new JPanel(new GridBagLayout());
List<ImageIcon> iconList = (List<ImageIcon>) value;
int xPos = 0;
for (ImageIcon icon : iconList) {
JLabel iconLabel = new JLabel(icon);
iconLabel.setToolTipText(icon.getDescription());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridy = 1;
gbc.gridx = xPos++;
iconsPanel.add(iconLabel, gbc);
}
iconsPanel.setBackground(isSelected ? table
.getSelectionBackground() : table.getBackground());
this.setVerticalAlignment(CENTER);
return iconsPanel;
}
return this;
}
}