JComboBox not updating the selected item

Hi, for some reason whenever I try to use the combo boxes in my main JFrame they do not update as expected. Instead, after clicking for the drop down menu and selecting a new item, it defaults back to the original selection.

The purpose for this program is to create a new table in a database based upon the selections by the user, and the combo boxes represent the table names pulled from the database.

I have noticed that while the table name combo boxes do not seem to work, the combo boxes for defining the where clause work exactly as expected.

Please note that some of the code was pregenerated as part of Netbeans IDE form editor.I will only include the code for one of the JComboBoxes as other than variable name, they are identical. All code used to create and initialize the code as well as change the list is as follows:

creation and init:

listTables1 =new javax.swing.JComboBox();

listTables1.setEnabled(false);

JCombo jc =new JCombo(listTables1, dcbm);// dcbm is an instantiation of DefaultComboBoxModel

listTables1.addItemListener(new java.awt.event.ItemListener(){

publicvoid itemStateChanged(java.awt.event.ItemEvent evt){

listTableChosen(evt);

}

});

*JCombo is a class i made thinking that the problem was with the setModel method of JComboBox. I overrode it with the following:

publicvoid setModel(ComboBoxModel aModel){

Object selection = aModel.getSelectedItem();

super.setModel(aModel);

setSelectedItem(selection);

}

After the user chooses the type of query that they want, I fill the table:

listTables1.removeAllItems();

listTables2.removeAllItems();

for(int i = 0; i < tabs.length; i++){

listTables1.addItem((Table) tabs[i]);//tabs represents the tables pulled from the database

listTables2.addItem((Table) tabs[i]);//The Table type comes from the schemacrawler api

}

listTables1.setSelectedIndex(0);//set the selectedIndex to be the first item

listTables2.setSelectedIndex(0);

the user then decides whether they want to pull from 1 or 2 tables

if(radOneTab.isSelected()){

listTables1.setEnabled(true);

listTables2.setEnabled(false);

}

if(radTwoTab.isSelected()){

listTables1.setEnabled(true);

listTables2.setEnabled(true);

}

finally, I added an itemlistener in the case that the events were not being handled properly:

if(evt.getStateChange() == ItemEvent.SELECTED){

JComboBox cb1 = (JComboBox) evt.getItemSelectable();

Table t1 = (Table) evt.getItem();

cb1.setSelectedItem(t1);

}

if(evt.getStateChange() == ItemEvent.DESELECTED){

}

If anyone can help me, that would be grand. I've been struggling with this for close to a week now.

[3990 byte] By [nightblade097a] at [2007-11-27 10:15:09]
# 1

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

camickra at 2007-7-28 15:37:47 > top of Java-index,Desktop,Core GUI APIs...
# 2

Working on it.......the program was originally ~2000 lines, so this may take a while

nightblade097a at 2007-7-28 15:37:47 > top of Java-index,Desktop,Core GUI APIs...
# 3

Unfortunately, I do not have the time it takes to try and rewrite the program so that I can replicate the problem. I posted this so that someone else could help me. If you need more information, please ask. But i simply don't have the time to sit down and either a) tear apart the program to find the cause, or b) create a whole new program that does what this one is doing. I need help, and if you feel you can't help me figure out the problem based on this information, then I guess I'll find somewhere else to get help.

nightblade097a at 2007-7-28 15:37:47 > top of Java-index,Desktop,Core GUI APIs...
# 4

> But i simply don't have the time to sit down and either

> a) tear apart the program to find the cause,

That is what problem solving is all about. Its about learning to simplify the problem to determine where the problem is. Once you do this you can then either solve the problem or post a new questions with the new information about what the cause of the problem is. You have not given us enough information to work with. There is no trick you using combo boxes, so you obviously have a programming problem. We can't guess what your 2000 lines of code is like which is why you need to simplify the code.

or b) create a whole new program that does what this one is doing.

Start by creating a 20 line program that does basically what you want. Once you've proved it works you then compare the working code with your real program to see whats different. It you can't get it working then you have a simple program to post. If you truly understand what you are attempting to do then you should be able to create a simple demo in 10-15 minutes.

If you can't take that time, then don't don't expect us to jump when you have a problem. Our time is just a valuable as yours.

I'll take one wild guess and refer you to this posting:

http://forum.java.sun.com/thread.jspa?forumID=257&threadID=428181

It shows how to update a combo box based on the selection of an item in a second combo box and show how easy it is to create a SSCCE.

camickra at 2007-7-28 15:37:47 > top of Java-index,Desktop,Core GUI APIs...
# 5

I'm sorry if I sounded like a whiny little kid. I'm running out of time before I have to present this at a half-formal meeting, and I've been on edge.

As for the simple program, I tried creating one and it worked, though honestly I think it may be the complexity of my actual program and all of the other stuff involved that is screwing me up. So, as you said, I need to simplify it, and that will be on my time.

By the way, thanks for the link, but unfortunately, the combo boxes in my case are independent of each other; they only share the same tables for the case that the user wants to link tables in a join for the data for the newly created table in the database.

Thank you for the reality check

nightblade097a at 2007-7-28 15:37:47 > top of Java-index,Desktop,Core GUI APIs...