Java Program using JList with ActionListener

In this program, You will learn how to implement JList with ActionListener in java.

JList jlist;

public void actionPerformed(ActionEvent e) { 

Example: How to implement JList with ActionListener in java.

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.JOptionPane;

class Test extends JFrame implements ActionListener {

    JButton jb1;
    JList jlist;

    Test() {

        String lang[] = {"India", "Eng", "Aus"};
        jlist = new JList(lang);
        jlist.setBounds(50, 30, 150, 80);

        jb1 = new JButton("Click");
        jb1.setBounds(50, 200, 100, 30);


        setSize(600, 500);

    public void actionPerformed(ActionEvent e) {
        String country = "";

        country = String.valueOf(jlist.getSelectedValue());

        JOptionPane.showMessageDialog(this, country);

    public static void main(String args[]) {
        Test t = new Test();


Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.