Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to move selected item from one default list to another defalut list
    primarykey
    data
    text
    <p>This is code, i have so far, so i want to move selected item from one list to another, Even i don't know , like in the second list, i need to getElement or addelement... please help me..you can just explain me, what can i do to move one element from list to another, by giving an example </p> <pre><code> //this is the code, just to the set the position GridBagConstraints gridConstraints; citiesLabel.setText("Destination City"); gridConstraints = new GridBagConstraints(); gridConstraints.gridx = 0; gridConstraints.gridy = 0; // below code is also set the position of the list gridConstraints.insets = new Insets(10, 0, 0, 0); getContentPane().add(citiesLabel, gridConstraints); citiesScrollPane.setPreferredSize(new Dimension(150, 100)); citiesScrollPane.setViewportView(citiesList); gridConstraints = new GridBagConstraints(); gridConstraints.gridx = 0; gridConstraints.gridy = 1; gridConstraints.insets = new Insets(10, 10, 10, 10); getContentPane().add(citiesScrollPane, gridConstraints); **This is my first list , which have all the values , that i want to move** final DefaultListModel citiesListModel = new DefaultListModel(); citiesListModel.addElement("San Diego"); citiesListModel.addElement("Los Angeles"); citiesListModel.addElement("Orange County"); citiesListModel.addElement("Ontario"); citiesListModel.addElement("Bakersfield"); citiesListModel.addElement("Oakland"); citiesListModel.addElement("Sacramento"); citiesListModel.addElement("San Jose"); citiesListModel.addElement("San Francisco"); citiesListModel.addElement("Eureka"); citiesListModel.addElement("Eugene"); citiesListModel.addElement("Portland"); citiesListModel.addElement("Spokane"); citiesListModel.addElement("Seattle"); citiesList.setModel(citiesListModel); citiesList.setSelectedIndex(0); </code></pre> <p>// this code sets the position of the selected list</p> <pre><code> SecondLabel.setText("Selected Cities"); gridConstraints = new GridBagConstraints(); gridConstraints.gridx = 1; gridConstraints.gridy = 0; gridConstraints.insets = new Insets(10, 0, 0, 0); getContentPane().add(SecondLabel, gridConstraints); SecondScrollPane.setPreferredSize(new Dimension(150, 100)); SecondScrollPane.setViewportView(SecondList); gridConstraints = new GridBagConstraints(); gridConstraints.gridx = 1; gridConstraints.gridy = 1; gridConstraints.insets = new Insets(10, 10, 10, 10); getContentPane().add(SecondScrollPane, gridConstraints); **This is my second list, which is empty, where i want to the moved value..** DefaultListModel citiesListModel1 = new DefaultListModel(); citiesListModel1.addElement("aa"); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); citiesListModel1.addElement(""); SecondList.setModel(citiesListModel1); SecondList.setSelectedIndex(0); **This is the button,for help me move selected city, from first list** AssignButton.setText("Add Cities"); gridConstraints = new GridBagConstraints(); gridConstraints.gridx = 0; gridConstraints.gridy = 2; gridConstraints.insets = new Insets(0, 0, 10, 0); getContentPane().add(AssignButton, gridConstraints); AssignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload