I have a JTable with a custom ListSelectionModel, which contains a custom selection mode. This selection mode ensures that a selection is only made in one row, but with multiple cells. When a user clicks selects some cells in the table, the selected cells are all in the same row as the first selected cell.
Now I want to create a small message above the upper-right corner of the leading selection cell, which displays some data, i.e. the count of the selected cells. The message should be moved when the leading selection is changed.
But how do I do that? It is not a Tooltip as it is intended to be shown when user clicks into the table and selects cells and not by hovering over it.
Any suggestions?
best regards,
htz
Alternatively (not very pretty but works quite well), you can take advantage of the fact that JTable is a JComponent like all others and therefore you can add child components to it. All you have to do, is make sure to size and locate properly your component (this is only because JTable uses a null-layout).
Here is a small demo with a JLabel that displays the number of selected items. The label is automatically positioned on the first visible row, unless it is the current lead selection, in which case, the label is moved to the second visible row: