Friday , February 23 2018
Home / java / Java JList Multiple Selection Example

Java JList Multiple Selection Example

In the previous tutorials, we have discussed about JList with single item selection. In this tutorial, I am going to show a most useful example how to use Java JList Multiple Selection mode.

Java JList Multiple Selection :

I am going to reuse the previous example here and enable multiple selection mode, and copy the selected items to another JList.

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.onlinetutorialspoint.swing.JListDemo;

public class JListCopyDemo extends JFrame {
    private JList jList;
    private JList jListForCopy;
    private JButton copyButton;
    private static final String[] listItems = { "BLUE", "BLACK", "CYAN",
            "GREEN", "GRAY", "RED", "WHITE" };
    private static final Color[] colors = { Color.BLUE, Color.BLACK,
            Color.CYAN, Color.GREEN, Color.GRAY, Color.RED, Color.WHITE };

    public JListCopyDemo() {
        super("JList Demo");
        setLayout(new FlowLayout());

        jList = new JList(listItems);
        add(new JScrollPane(jList));
        copyButton = new JButton("Copy>>>");
        copyButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        jListForCopy = new JList();
        add(new JScrollPane(jListForCopy));
    public static void main(String[] args) {
        JListCopyDemo jListDemo = new JListCopyDemo();
        jListDemo.setSize(350, 150);

Output :

Java JList Multiple Selection

JList Multiple Selection :

Java JList Multiple Selection 1

Copy JList Multiple Selection :

Java JList Multiple Selection 2

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,


Java String to int conversion Example

In this tutorial we are going to see how to convert Java string to int. …

Leave a Reply

Your email address will not be published. Required fields are marked *