• Post Reply Bookmark Topic Watch Topic
  • New Topic

Kludge or NOT Kludge JTable DnD

Jim Crowell
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an 'AbstractTableModel' subclass that display 3 columns with Drag & Drop processing from a center column cell [Drag] to a right most column cell [Drop]. The Table Model manages an ArrayList<String> component that holds the row, column parameters.

I have a 'TransferHandler' subclass that services the above DnD capability. It contains 'Override' methods for the following methods:
createTransferable; exportDone; canImport; importData;

The Table Model also is designed to insert a new row if the Drop column element has a non-null String. This is accomplished in my 'importData' override method. I add a row of data to the ArrayList and increment the Table Model 'nRow' parameter.

My problem is that when the 'AbstractTableModel' listener invokes my 'exportDone' override method the JTable component derived from the 'exportDone' 'JComponent' argument is still set to the 'Drop' column before the row was added.

I tried selecting the next row of the JTable in the 'importData' override method and in the 'addRow' method of the Table Model to no avail.

I could not find a better way to fix this so I coded what looks like a 'kludge' [to me]. The 'kludge' works fine but I am wondering if there is a better way to manipulate the JTable instance so that the 'exportDone' will be given the adjusted row index.

The 'kludge' is to set a boolean flag [fAddedRow] in my 'addRow' Table Model method and to use that flag in my 'exportData' override method to increment the row iff the flag is set.

The following is my code for the AbstractTableModel and the TransferHandler:
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!