Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

B&S: How to know which record in search Jtable is selected  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have two table models one which contains all the data, second contains search data. I want to know how do you know which record have been selected from search table as it is a subset of the whole data and we don't have record numbers associated?
Is the solution to this problem is to introduce record number while fetching the data from the file?
or something else?
:roll:
Please reply
Thanks
Madan
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by K Madan:
Hi all,
I have two table models one which contains all the data, second contains search data. I want to know how do you know which record have been selected from search table as it is a subset of the whole data and we don't have record numbers associated?
Is the solution to this problem is to introduce record number while fetching the data from the file?
or something else?
:roll:
Please reply
Thanks
Madan



This question has puzzled me mightily, but finally I solved it by dusplaying the record number in the GUI as the first element of the array - and converting records to and from a string array containing or not containing the record number. It is very inefficient, and some people would argue that the record number does not need to be seen at all, but with a thin client, this would be an only solution that I could think of.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a HashMap in the table model to keep track of row number/record number.

Some of the methods in the parent model(DefaultTableModel) have to be overriden of course.

bw
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ben wung:
I used a HashMap in the table model to keep track of row number/record number.

Some of the methods in the parent model(DefaultTableModel) have to be overriden of course.

bw



I keep my records in TransferObjects that contain a record number. I don't display the record number to the user, but row[n] is held in object[n] which contains the record number.

Originally I was keeping a Map of record to row numbers to help find records when updating after booking a room. The complexity of this rose when I added insert and delete and sorted data. Now all I do is keep the most recently referenced row number and look there first, if not found I do a sequencial search. This should be faster than the Map solution since I'm almost always replacing the row i referenced last.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My model class accesses a collection of DTOs from getValueAt(). Each DTO has a "key" member, which is populated by reads() and finds() via a DAO which wraps the Data class. Since it's a Flatfile DAO the key is naturally populated by a record number from the database. If it was a RDBMS it would be an _id column, etc.

When the controller fires the book() method, it passes the key value from the DTO in the model to the DAO. The Flatfile DAO in this case understands the key as a record number, and calls the low-level Data class that way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!