NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Data Binding: Finding an object in the master table

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
greyspammer



Joined: 15 Dec 2009
Posts: 3

PostPosted: Tue Dec 15, 2009 4:50 pm    Post subject: Data Binding: Finding an object in the master table Reply with quote

Hello!

I'm just getting myself acquainted with Netbeans' data binding. The normal data binding worked fine in my example application.

Now I have the following scenario: Let's call the JTextField which displays the key of the (currrently selected) object "jID". When the user enters a value there, the application should check if an object with that key already exists and select it automatically in the master table - thus also filling all the other fields with the associated values. Or I just have a long table and want to search for something instead of scrolling around.

I looked at the API docs and am currently not sure what the best approach would be. Perhaps you give me a little push in the right direction.

I could use the entity manager to get a reference to the persistant object with the given key. But how would I tell the master table to select it? I would need to know what index that object has in the table in order to use the method provided by the ListSelectionModel interface. However, I see no way to do that. The TableModel interface provides no method "getIndex(Object o)" or somesuch.

Another possible approach would be to find the key in the table itself. I would have to find the column index which displays the key (they can be rearranged after all) and then go through all the rows until getValueAt(row,indexColumn) equals the search key. But that would be a linear search. I hope the data behind the table is organised in a way that would allow better option (i.e. a HashMap). Alas, the data structure that feeds the master table seems to be hidden from my access.

Is either method what I'm looking for or I'm I totally wrong with them? What documentation did I forget to read?

Thanks in advance.
Back to top
greyspammer



Joined: 15 Dec 2009
Posts: 3

PostPosted: Fri Dec 18, 2009 12:19 pm    Post subject: Reply with quote

I think the best solution so far is to use the private List that is auto-created to the form to get the index of the item and then select it.

However, that probably means I cannot use any table row sorters because the List has no knowledge of how the JTable arranges its data.

If anyone has any better ideas, I'm open to suggestions.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo