I want to transfer the selected objects from one JList to another JList, say List1 and List2.
Here I am showing you example of transferring name of cities from list
to list_1
. You will receive output something like this:
Code for this is :
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.DefaultListModel;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ListTransfer {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ListTransfer window = new ListTransfer();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ListTransfer() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
String[] values = new String[] {"Surat", "Ahmedabad", "Vadodra", "Anand", "Bharuch", "Maninagar", "Mumbai", "Pune", "Hydrabad", "Banglore"};
DefaultListModel