Results 1 to 3 of 3
  1. #1
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Problem: Fill a comboBox from another combobox

    I have 3 combobox.
    I would fill the 2nd ComboBox depending on the element in the first select. Then the same thing for the third based on the 2nd.
    I used action listener and I called in actionPerformed
    My code runs fine but I have a problem to remove the old items in each combobox, I received the following error message:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at test.Prin$Deuxieme_combo.actionPerformed(Prin.java:154)
    the error is in the second combo
    java : 154
    Java Code:
     if(ComboB.getSelectedItem().equals("C"))
    my code for the first combobox is as follows:
    Java Code:
    lass Premier_combo implements ActionListener
    {
    
            @Override
            public void actionPerformed(ActionEvent e) {
               if(ComboA.getSelectedItem().equals("A"))
              { 
            ComboB.removeAllItems();
                ComboB.addItem("C");
              }
       else
                   if(ComboA.getSelectedItem().equals("B"))
              {
               
                   ComboB.removeAllItems();
              ComboB.addItem("D");
              } 
            }
    
          
    }
    Java Code:
    private void ComboAActionPerformed(java.awt.event.ActionEvent evt) {
    Premier_combo  premier = new Premier_combo();
    
    ComboA.addActionListener(premier);
        }
    code is the second combobox following:
    Java Code:
    class Deuxieme_combo implements ActionListener
    {
    
            @Override
            public void actionPerformed(ActionEvent e) {
                 if(ComboB.getSelectedItem().equals("C"))
              {
             ComboC.removeAllItems();
                ComboC.addItem("E");
              }
       else
                   if(ComboB.getSelectedItem().equals("D"))
              {
             
                  ComboC.removeAllItems();
              ComboC.addItem("F");
              }  
            }     
    }
    Java Code:
     private void ComboBActionPerformed(java.awt.event.ActionEvent evt) {
    Deuxieme_combo deuxieme= new Deuxieme_combo();
    
    ComboB.addActionListener(deuxieme);
                
        }
    my problem is normally at removing old items but I have not found another solution because I need to remove the old ones.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: Problem: Fill a comboBox from another combobox

    I am not certain what the problem is because you did not include all the code. However, why are you adding a new actionListener everytime you get ComboActionPerformed event?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Problem: Fill a comboBox from another combobox

    I agree with Jim. To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. ComboBox Fill From Mysql
    By kevinn205 in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2011, 08:43 PM
  2. Which combobox event to use to fill a textbox
    By aborgeld in forum New To Java
    Replies: 4
    Last Post: 01-03-2011, 05:18 PM
  3. Combobox Problem?
    By waqasahmed_03235001393 in forum Advanced Java
    Replies: 1
    Last Post: 07-27-2010, 10:56 AM
  4. problem in combobox
    By 435.mahesh in forum AWT / Swing
    Replies: 3
    Last Post: 05-04-2009, 05:12 AM
  5. Problem in combobox
    By santhosh_el in forum AWT / Swing
    Replies: 4
    Last Post: 04-03-2009, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •