Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Urgent JComboBox!!!

 
Friend
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
JComboBox problem is severly affecting me. I need only one value from JComboBox at a time. But when I selecting an item from it, that item is fired 2 times.Please give me a solution for this. Any other way ?
Thank you.
 
Udayan Naik
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jyotsna.If u need only the value from the combo box,i think there must be a getSelectedItem() or it's equivalent method in there Swing/JFC library.I dont thing the number of times an event will fire should affect your selected value.
You could also check out the Swing Bug database on java.sun.com.
 
Friend
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Uday,
Your answer is not satisfactory for me.I think you didn't understand my problem.I have used getSelectedItem() methos.When using this method I got the value from the Combo.But The System.out.println(item) is printing this item value two times.
 
Udayan Naik
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jyotsna.Maybe if you can clearly state the exact problem u are facing,I may be able to help u.I'm afraid I still don't get the problem.
How exactly is printing the value 2 times causing a problem.What is the requirement?
 
Julie Stella
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what event are you calling getSelectedItem()? If you are calling it from an action event, the event is fired twice...once when the combo box is selected and once when a new value is selected from the drop down of the combo box.
HTH
stella
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into the same problem. It seemed that itemStateChanged was getting fired twice when the user selected an item from the JComboBox. What happens is itemStateChanged IS being fired twice: once when the original selected item is DESELECTED, and once when the new item is SELECTED. Try doing this:

Hope this helps!
 
Friend
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Verduka,
Thanks for the response.But I tried this also.I have two Comboboxes.Then this also makes problem for me.The two combo values are passing to the servlet.While it takes the same value,that means any one of the combo values are storing to the database.But the firing problem vanished.Not identifying the comboboxes in the servlet.
Jyotsna.
 
Takeshi Toyohara
Greenhorn
Posts: 21
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If u r using the itemStateChanged() event then it will be fired twice when u select an item. However this is not a bug. It is fired first when the curently selected item is changed. and it is fired next whne a new item is selected (quite logical)
 
red goliath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jyotsna,
I think getSelectedItem() method must satisfy ur requirement.if u are using item changed , u will get it twice as the firing of events is done twice.
take this implementation in my project.
i have to get the value in two JcomboBox on click of ok button and send it for proceesing.
Sample :

public void actionPerformed(ActionEvent ae){
String choice = ae.getActionCommand();
.......
table = (String)cbTableName.getSelectedItem();
operation= (String)cbOperation.getSelectedItem();
table = table.trim();
operation = operation.trim();
// both table and operation are strings
...................
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!