I want to display a text above a JTable cell when someone is editing the cell. The text is pretty much the same as a tooltip with the exception, that the text should only be displayed when editing a cell and the text should stay until the editing is finished.
How could I achieve such a behaviour?
What I have tried so far is to override the getCellEditor method of JTable but that will only set the standard tooltip, but I need to display the text permanently for the time of the editing.
@Override
public TableCellEditor getCellEditor(int row, int column) {
TableCellEditor editor = super.getCellEditor(row, column);
Component component = editor.getTableCellEditorComponent(this, getValueAt(row, column), isCellSelected(row, column), row, column);
if(component instanceof JTextField) {
JTextField textfield = (JTextField) component;
textfield.setToolTipText("tooltip");
}
return editor;
}
Another option would be to also add a JLabel (or any component) when you start editing a cell. Whenever it stops, you remove the component.
Because you want the tooltip/label to appear above the edited cell, it requires a little trick for the first row.
Here is an example showing what I mean: