• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Event Handling

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do a small things.
I have a table like this
Type1 SubType1 Temp1 SubTemp1
Type1 SubType2 Temp2 SubTemp2

I have created a frame where there are 2 comboboxes and 2 textfield
COmboBox1 wil have field 1 and combobox will have field2.
Depending on the valuess chosen in field1 the combobox2 should get updated and depending on the 2 comboboxes the textfield should get field
I have writen ItemStatehanged event, When the item state of the first combo box , first thing I do it
Combobox2.removeAllItems();, then go ahead the fill the Items of combobox2 with new values depending on combobox1 selected.
But the problem I am having is when I change the item in First combo box , the removeAllItems(); fires the event on the second box also and then it creates a problem.
I tried everything, nothing works.
Ccan anybody read the code which I am attaching and give me the solution. or if anyone has a other solution to implement this please help me.
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent
event)
{
Object object = event.getSource();
if (object == JComboBox1){
JComboBox1_itemStateChanged(event);}
else if (object == JComboBox2){
JComboBox2_itemStateChanged(event);}
}
}
void JComboBox1_itemStateChange (java.awt.event.ItemEvent event)
{
JComboBox2.removeAllItems();
fillCombo2(JComboBox1.getSelectedItem().toString());
fillOther(JComboBox1.getSelectedItem().toString(),JComboBox2.getSelectedItem().toString());

}
void JComboBox2_itemStateChanged(java.awt.event.ItemEvent event)
{

fillOther(JComboBox1.getSelectedItem().toString() ,JComboBox2.getSelectedItem().toString());
}

Here fillComboBox2 , reads the database and fills the second combobox and fillOther is suppose to fill the other 2 textfields.

}
}
[This message has been edited by Milind Deodhar (edited March 28, 2001).]
[This message has been edited by Milind Deodhar (edited March 28, 2001).]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if it's what you want, but here is something.
I too had a great deal of trouble with this code, it was constantly throwing exceptions and misbehaving, until I made the discovery that is included in a rather large comment.

[This message has been edited by Mike Curwen (edited March 28, 2001).]
 
Milind Deodhar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your reply
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using similar code with comboboxes. Every time an item is selected from a combobox, a new query is executed and it populates other comboboxes and the second combobox affects the third...
I am using ActionListeners instead of ItemListeners and things seem to be working alright. Thanks for that.
 
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic