aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About combo boxes and refressing data UrlyBird Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "About combo boxes and refressing data UrlyBird" Watch "About combo boxes and refressing data UrlyBird" New topic
Author

About combo boxes and refressing data UrlyBird

Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
I have mulled this over and over, and am not sure it is necessary to refresh the data in the combo boxes (one for Hotel name selection, and one for Hotel location selection). I think that it is OK not to, because if the room is already reserved, they are going to see it in the table (the owner id field will have numbers in it, not be blank). I display a message if it is deleted (they can't delete anyway), or if they decided to go ahead and try to reserve an already reserved room. I will document it in choices.txt. People have gotten away with a lot of other things that might not be appropriate in the real world with a good explanation in the choices.txt. The other issue that came to mind was duplicates in the combo boxes. I decided to leave that one alone, too. The boxes get their data right from the table. A click of the search button will return a new set of data, whole new read of table and new model. I couldn't find much on this with a search both on this site and on the internet in general. Any thoughts appreciated.


SCJP, SCJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

Hi Anne,

Ah, this discussion again

If i understand you correctly the data in the comboboxes is taken/refreshed from the JTable containing all matching records. So if you do a search, Table is filled with another set of data and combo boxes are refreshed with data from the JTable. Is my understanding correct? If it is, I'll have some doubts about it.

Nonetheless I would certainly not allow duplicates in my comboboxes, because that will confuse a user: why is "Ritz" 3 times in the combo? Will a search on each occurence have another result.

Kind regards,
Roel

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
OK, Roel, you've got me working on using a set to hold the strings that go in the box models (No duplicates). Good in theory, but not working. It's allowing duplicates, basically the same thing that I already have. I'm pretty sure the problem is that since I am dealing with Strings, equality of content and equality are not the same thing. The Strings have the same hotel name but are actually a different Object, so the set is allowing the dupes. I gave up and went home. Back to the drawing board tomorrow. I'm amazed at how much I don't know about Swing
Axel Leucht
Greenhorn

Joined: Jan 19, 2009
Posts: 21
I'm doing also the combo box approach. I also thought about refreshing the boxes as they might not reflect the database state. I come to the conclusion not to bother with it as a client might never be sure to see the latest state of the database anyway! That's why I have my combo boxes made editable, so even when the entry is not displayed the user can still type in what he liked to search for. I populate them once when the application starts and has to perform a search for all records anyway.

You're second problem with having dupes in the combo boxes, I also think this to be weird for the user experience. So I'm using a java.util.TreeMap and add all found entries to it and return a String-array from my helper method. The combo box are then filled with the contents of the array. This avoid the dupes and gives the additional advantage of the combo box being sorted.

Hope that helps.


Regards

SCJP, SCJD
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

Hello Anne, the duplicates in the combo box should not have anything to do with Swing components. It's on how you getting that data from the database file. Since you are using strings, have you thought of using collections? Working with lists, sets or maps are easier to manipulate, iterate etc.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5216
    
  12

Anne Crace wrote:OK, Roel, you've got me working on using a set to hold the strings that go in the box models (No duplicates). Good in theory, but not working. It's allowing duplicates, basically the same thing that I already have.


That's weird it isn't working. Because if I use the following program which uses a set (TreeSet to sort alphabetically) only 4 names are printed to the console (although i add 6 strings to the set). I'm a bit that it isn't working with you.



Kind regards,
Roel
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
I got it working. I was having some scoping (curly brace location) issues as far as where everything was happening. I ran it through the debugger to see that the set was indeed correct (all unique). I just needed to put the set back into an array to load the boxes. Now I have a slight bug in my Search algorithm, but don't think that will be so difficult to fix. All in all, a good learning experience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About combo boxes and refressing data UrlyBird