1

I have this ComboBox which I want to fire a selected option upon runtime, I know to fire a button action by using button.doClick(), but how can I do this in a ComboBox action event?

This is my ComboBox event:

comboBox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {

        if(filters.isEmpty())
            filters.add(RowFilter.regexFilter(comboBox.getSelectedItem().toString(), 2));
        else
            filters.set(0, RowFilter.regexFilter(comboBox.getSelectedItem().toString(), 2));

        // Apply filters
        sorter.setRowFilter(RowFilter.andFilter(filters));

      /*  comboBox.setSelectedItem("BAR");*/
    }
});
Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
Arturo Martinez
  • 389
  • 7
  • 28
  • 1
    Try having a look here see if this helps [link](http://stackoverflow.com/questions/14306125/how-to-use-actionlistener-on-a-combobox-to-give-a-variable-a-value) – PSD May 13 '16 at 03:05
  • *"which I want to fire a selected option upon runtime"* - why not just run the code that the option runs outside of the action listener, like in the constructor, and mark the option as selected? – Jonny Henly May 13 '16 at 03:13
  • Pull the code out of the listener anon class, call it from wherever you need it. This is much simpler than trying to directly simulate the UI pipeline from your program. – pvg May 13 '16 at 03:15
  • Possible duplicate of [onChange and onSelect in DropDownList](http://stackoverflow.com/questions/9935134/onchange-and-onselect-in-dropdownlist) – Tibrogargan May 13 '16 at 03:33
  • already marked my selected option on combobox but it dont triggers my action unles i select something after runtime @JonnyHenly – Arturo Martinez May 13 '16 at 04:14
  • @Tibrogargan that question applies to html and javascript, not Java. – Jonny Henly May 13 '16 at 04:15
  • @ArturoMartinez I'm suggesting not to go about it by triggering the action, instead run the code that the action triggers outside of the action listener prior to presenting the ComboBox. – Jonny Henly May 13 '16 at 04:22
  • Is not working if i do as you suggest @JonnyHenly does anybody has an examplo where you trigger a jcombobox action? – Arturo Martinez May 13 '16 at 04:51

0 Answers0