Skip to main content

Turn Off Sorting for JTable TableModel Insert?

3 replies [Last post]
rayvermette
Offline
Joined: 2006-01-01
Points: 0

Greetings,

I have an editable, sorted JTable with a custom TableModel that allows the user to insert/update/delete. When the user chooses to insert a new row, a blank row is added to the end of the TableModel. I would like the row to appear at the bottom of the JTable. Unfortunately, the sorter sorts this blank row to the top of the JTable.

Is there a way to turn off sorting when rows are inserted in the TableModel? I found the "setSortsOnUpdates()" method, but there appears to be no comparable "setSortsOnInserts()" method.

Any recommendation on how best to turn off sorting when inserting rows in the underlying TableModel? Would the Mustang developers consider adding a "setSortsOnInserts()" method?

Thanks in advance for any help and thanks for your efforts. The new JTable filtering and sorting features are much appreciated!

Ray

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tackline
Offline
Joined: 2003-06-19
Points: 0

The obvious way to make new rows appear at the end is to sort first on a hidden column. The value can be cleared at a time appropriate for the application. The technique has the major advantage that concurrent updates to the table will still work.

From a usability stand point, I don't think scrolling to the bottom of a sorted table when adding a new record makes much sense. Better would be to add to a matching, headerless table outside of the scrollable area.

rayvermette
Offline
Joined: 2006-01-01
Points: 0

Thanks. Suggestions from others?

gernot
Offline
Joined: 2003-06-23
Points: 0

You can use something like a dialog box to let the user enter the row data. If the user submits the data, the row is inserted accordingly.

--
Gernot