java - How do I load a JComboBox with values from an Array or ArrayList? -


Text after "div class =" itemprop = "text">

I need to put the following array in a JComboBox and then the selected value is stored when the "Send" button needs to be clicked .

  listOfDepartments = new string [5]; ListOfDepartments [0] = "Men's Clothing"; ListOfDepartments [1] = "Women's Clothing"; ListOfDepartments [2] = "Children's Clothing"; ListOfDepartments [3] = "Electronics"; Catalog of departments [4] = "toys"; // Department: ComboBox loads from that array // store JButton buttonSubmit = New JButton (); ButtonSubmit.setText ("send"); Container.add (buttonSubmit); ButtonSubmit.addActionListener (New ActionListener) {@Override Public Zero actionPerformed (ActionEvent evt) {// store value from combo box in a variable}});    

"itemprop =" text ">

First, create a model ...

  DefaultComboBoxModel Model = New DefaultComboBoxModel (listOfDepartments); ComboBox.setModel (model);   

Second, get the selected code when action-driven event is picked up ...

  string value = (string) comboBox .getSelectedItem ();   

For more information, take a look at.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -