aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: How to know which record in search Jtable is selected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: How to know which record in search Jtable is selected" Watch "B&S: How to know which record in search Jtable is selected" New topic
Author

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

K Madan
Greenhorn

Joined: Apr 08, 2004
Posts: 10
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
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
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.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Ben Zung
Greenhorn

Joined: Sep 16, 2004
Posts: 8
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
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
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.
Robert Chisholm
Ranch Hand

Joined: Jul 18, 2004
Posts: 69
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.


SCJP 1.4<br />(WIP) SCJD B&S v2.3.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: How to know which record in search Jtable is selected