1

I have a JTable in my GUI. In our system, there are various registrar. If a registrar adds a data, this data is added to a cell in the JTable.

If I simply add this data to the table, I lost the registrar information, which is very important for further operations.

What I try to do is that I need to add an extra information (who registered this data) to each cell in the JTable but this extra information should not be seen in the table.

Briefly. If a cell is selected, I should access the registrar information.

I do not know whether it is possible to implement something like but any help and suggestions will be appreciated.

Ad Infinitum
  • 3,560
  • 27
  • 33
  • `What I try to do is that I need to add an extra information` - question, is/are this/those data stored in `XxxTableModel` (its can't be dispayed in `JTables` view), otherwise you'll bothering with *** – mKorbel Jun 28 '16 at 11:30
  • However, each cell has a different data. It is more or less like `HashMap`. The value in the cell is a kind of key, the registerer info for this specific cell is like a value. Because, the table I use is a very dynamic table and it changes itself continuously. Because of this reason, these datas should be tied to eachother. – Ad Infinitum Jun 28 '16 at 11:43
  • ok this is your decision, no idea for why reason(s) there are two models (could be very important in the case that content is dynamics), then by assuming that AbstractTableModel is based on this HashMap, hint - use todays array - List/LinkedList, rest is very good decribed in answer by @trashgod (as always:-) – mKorbel Jun 28 '16 at 12:54

1 Answers1

3

One appproach would be to display the extra details in a tooltip. The article How to Use Tables: Specifying Tool Tips for Cells includes a complete example that shows how to change the tooltip text for each cell. You could keep the registrar information in your TableModel and get to it in your TableCellRenderer via the table parameter seen by getTableCellRendererComponent(). Alternatively, display it in a TablePopupEditor, seen here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you very much for your answer. Actually, my problem was much more difficult than I wrote here. Because of this reason, I solved my problem differently. I accept this as solution because I think it is a good solution to what I wrote here. – Ad Infinitum Jun 30 '16 at 07:28
  • @AdInfinitum: I'm glad you got it sorted; ping me here if you also [answer your own question](http://meta.stackoverflow.com/q/17463/163188), and I'll update accordingly. – trashgod Jun 30 '16 at 08:32
  • Mainly, I have used `Map< Integer, List>` . `Integer` here represents the indexes (first row = 0, second row=1 and goes on like that) in the table and list holds the cells (registrar info), which belongs to the corresponding index. If a user wants to edit a cell, from row number, I get the corresponding list from the map and by using the column number, I get the registrar info from the list. – Ad Infinitum Jun 30 '16 at 09:18