title: How to identify the source of an event..?
body: <p>Does the method <code>JComboBox.removeAllItems()</code> in turn fire an ItemStateChanged event..?<br>
  If so, how do i determine weather the event is generated due to the user action or due to the invocation of the method removeAllItems()..?<br>
  I have some code in the itemStateChanged() method of a combo box, which will work fine when the user changes the his selection in the combo box, but by the nature of code, it throws a null pointer exception when it is called due to the invocation of removeAllItems() on that combo box. If i can determine the cause for the event to be removeAllItems() method and return the control, then my problem would be solved. How do i do this..?<br>
  <strong>UPDATE</strong><br>
  After you people have put up the answers, i used the following code...</p>
  
  <pre><code> @Override
          public void itemStateChanged(ItemEvent e) {
              if(e.getSource()==branch_list)
              {
                  if(!UserConstants.FID.contains("hod"))
                  {
                      ignoreEvents=true;//static boolean variable not used by any other methods
                      year_list.removeAllItems();
                      year_list.addItem(" ");
                      sem_list.removeAllItems();
                      sem_list.addItem(" ");
                      branch_list.removeAllItems();
                      branch_list.addItem(" ");
                      if(branch_list.getSelectedItem().equals(" "))
                          return;
                      Iterator year_it=DatabaseConnector.map.get(branch_list.getSelectedItem().toString()).keySet().iterator();
                      while(year_it.hasNext())
                      {
                          year_list.addItem(year_it.next());
  
                      }
                      ignoreEvents=false;
                  }
                  return;
              }
              else if(e.getSource()==year_list)
              {
                  if((branch_list.getSelectedItem()==null)||branch_list.getSelectedItem().toString().equals(" ")||ignoreEvents)
                  return;
                  sem_list.removeAllItems();
                  section_list.removeAllItems();
                  sem_list.addItem(" ");
                  section_list.addItem(" ");
                  Iterator i=DatabaseConnector.map.get(branch_list.getSelectedItem().toString()).get(year_list.getSelectedItem().toString()).iterator();
                  int first=0;
                  while(i.hasNext())
                  {
                      String cur=i.next().toString();
                      if(first==0)
                      {
                          sem_list.addItem(cur.charAt(0));
                          section_list.addItem(cur.charAt(1));
                          first++;
                      }
                      else
                      {
                          section_list.addItem(cur.charAt(1));
                      }
  
                  }
  
  
              }
  
          }
  I am getting the following error:-  
  Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
      at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(SingleByteEncoder.java:91)
      at sun.nio.cs.SingleByteEncoder.encodeLoop(SingleByteEncoder.java:130)
      at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:544)
      at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:252)
      at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
      at java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
      at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
      at java.io.PrintStream.write(PrintStream.java:476)
      at java.io.PrintStream.print(PrintStream.java:619)
      at java.io.PrintStream.println(PrintStream.java:756)
      at attendence.Home.itemStateChanged(Home.java:427)
  </code></pre>
  
  <p>and so on...........</p>