JTable with fewer lines than displayed and sorting problems

I am using a JTable object to display some data stored in a database. Now I would like to get the following result:

The displayed JTable should have at least n (let it be 10) rows, even if my db table has fewer records. An empty row should always be displayed at the end of the table.

Now I do the following:

I implemented my own tab model extending AbstractTableModel. And in the implemented getRowCount method, I did:

public int getRowCount() {
       if (myRowCount < 10 )

           return 10;
       else 
           return myRowCount;
}

Questions:

  • This code works fine, but I was wondering if this is the right approach to achieve this result. Is this a good solution?
  • , . , -, , , (, colum of int ) . TableRowSorter, , (table.setAutoCreateRowSorter(true))?

EDIT: @mKorbel @kleopatra @camickr . . , . , , ? , ?

. , ! ..

Marco

+4
1

, , - DefaultRowSorter getComparator(column).

EDIT , getComparator(), Comparator , , null .. , , DefaultRowSorter , .

, DefaultRowSorter , . , RowSorter. , .

+3

All Articles