Hello,
I'm trying to set up a JTable with tool tip text on each of its cells using a custom renderer. I have that part down just fine, but I'm trying to tweak it so the delay of the tool tip applies to the individual cells, not the entire table.
As of now, if you mouse over a cell in the table, the appropriate tool tip text pops up after the delay. Fantastic. However, if you then move your mouse into another cell, the tool tip for the new cell pops up immediately instead of waiting for a delay. The only time that delay occurs is if you move your mouse outside the JTable and then back in. But going from cell to cell gets rid of the delay. I understand
why this is happening, but how can I make it
not happen?
My other tiny issue is this: if multiple cells have the same tool tip text, the tool tip square doesn't follow the mouse as it goes over different cells. Is there a way to change that behavior?
Some compilable code demonstrating the stuff I'm talking about:
import javax.swing.*;
public class TestTable{
public static void main(String [] args){
ToolTipManager.sharedInstance().setReshowDelay(0);
JFrame frame = new JFrame("Testing Table");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTable table = new JTable(2, 3);
TestTableRenderer testTableRenderer = new TestTableRenderer();
table.setDefaultRenderer(Object.class, testTableRenderer);
JScrollPane scroll = new JScrollPane(table);
frame.getContentPane().add(scroll);
frame.setSize(200,200);
frame.setVisible(true);
}
}
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
public class TestTableRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setToolTipText("row: " + row + ", col: " + column);
//change the line to this to see problem 2:
//setToolTipText("cats");
return cell;
}
}
Any help on either of these small but annoying issues would be much appreciated. Thanks!