-4

So I have this project,

the source code is here.

When you run the project and goto Processing, there is a jcombobox there that is suppose to have an addActionListener.

p_customer_list = new JComboBox<>(customers_name);
    pp_customer_list.setPreferredSize(new Dimension(360, 35)); 
    panel_processing_header.add(pp_customer_list);
    //pp_customer_list.addActionListener(this);
    pp_customer_list.addActionListener (new ActionListener () {
        public void actionPerformed(ActionEvent e) {
            JComboBox tmpBox = (JComboBox) e.getSource();
            int selected = tmpBox.getSelectedIndex();
            pp_refresh_data(selected);
        }
    }); 

This is what I have so far, its suppose to find the selected index when the value of the combobox changes and pass it to pp_refresh_data() but for some reason it does not run (I tried putting a JOptionPane to see when the code is executed, and its only executed once when the program runs.)

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Ahoura Ghotbi
  • 2,866
  • 12
  • 36
  • 65
  • Why are you getting the source of the ActionEvent when you know it is the pp_customer_list? Just make the JComboBox final and use it inside the listener. Also please don't use underscores with names UNLESS all of its letters are capitalized. Otherwise just use something like pCustomerList. – Kakalokia Mar 25 '13 at 13:17
  • 1
    @AliAlamiri grabbing the source from the event (with appropriate guarding agains a classCastException) is A-Good-Idea - decouples code. – kleopatra Mar 25 '13 at 13:29
  • unrelated: [don't use setXXSize, ever](http://stackoverflow.com/a/7229519/203657) – kleopatra Mar 25 '13 at 13:30

1 Answers1

1

Hard to tell from just a partial code snippet, but do you have 2 combos, one named "p_customer_list" and another named "pp_customer_list"?

This could be your problem. You may be adding the listener to the wrong combo, or you may be adding the wrong combo to your panel, or maybe you don't need two, or maybe...

Again, it's hard to tell from just a snippet.

splungebob
  • 5,357
  • 2
  • 22
  • 45