Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 760613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:44:20+00:00 2026-05-14T15:44:20+00:00

I have a JTable filled with data of a table of my database (so

  • 0

I have a JTable filled with data of a table of my database (so I used ResultSetTableModel) and using TableRowSorter to sort the rows, as I click in one column of the JTable. The data is displayed in the jTable without problems;

But when I sort the JTable by some column table (for example, sorting it by the primary key value), and edit some cell from the sorted jTable, the value changed is the old cell that were in that position before the ordenation of the column.

For example:
Suppose I have a table with 2 columns – name and age. My table has the following data:

c 1
b 2
a 3

when I order i by name in the JTable, it becomes like this

a 3
b 2
c 1

if I edit the value “1”, after the edition, the table becomes like this

a 1
b 2
c 1

It seems that the positions are not being updated in the JTable, and the values are edited considering their original positions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:44:21+00:00Added an answer on May 14, 2026 at 3:44 pm

    Firstly, note that data is actually contained in the model and jtable is just a view.
    Normally, by default the jtable’s rows and columns correspond to rows and columns of the table. When you sort, this mapping between jtable’s row,col may not remain the same,
    so when you want to edit say cell(rowVal,colVal),
    do

    table.setValueAt(object,table.convertRowIndexToModel(rowVal),convertColumnIndexToModel(colVal))
    

    this should preserve the mapping after sorting.
    Read the section Sorting and Filtering here: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable of which one column is pre-filled with 30min time slots
I have a JTable that is using a TableColumnModelListener() to detect when the column
I have a JTable that loads data from a database. Because sometimes there's too
I have a table called table and its filled with data, I also have
If you have JTable set with table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) and then you click drag on a
I have a JTable that will have the last column data field change to
I have a JTable where one column occasionally has a fair amount of text
I have a jtable, everything works fine if I set the table data as
i have one jtable with listselectionlistener i can dynamically added the new rows in
I have a jTable which currently displays and allows editing of a database table,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.