Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

delete a row from Jtable When  RSS feed

 
venkat anand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Jtable with data and storting functionality with that.Sorting order is desc ,asc,normal(i used one i got from net is :TableSorter.java).When i click the header for sorting other than the normal i need to hide/remove one ROW (second column has value constant for that row) from my table,when it come to normal display i need to reinsert/unhide that deleted row?Suggestions are greatly appreciated.
Thanks
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Java 6, there are two classes you can use for this: javax.swing.table.TableRowSorter and javax.swing.RowFilter

The TableRowSorter can have a Comparator per column, allowing you to have the JTable do the sorting for you. With the setSortable method you can enable or disable sorting for columns as needed.

It also has a method called setRowFilter, which takes a RowFilter<? super M,? super I>, where M is TableModel or an implementation thereof, and I is Integer. You can use one of the static methods, or create a subclass that overrides the include method.

The include method takes one parameter, of type javax.swing.RowFilter.Entry<M,I>. You can get the model using the getModel method, and the row number using the getIdentifier method. With that, you can determine whether or not the row should be shown or not, without removing it from the model.
 
venkat anand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,,
Thanks for you reply..sorry,,i fogot to tell one thing that i Must use the JDK 1.4
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!