JList

The JList class is a single or multiple selection which list with multiple elements.

Program

sdsd

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import java.awt.FlowLayout;

class Frame extends JFrame {
   
    Frame()
    {
        setTitle("JList");
        setLayout(new FlowLayout());
        setJList();
        setSize(700,250);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJList()
    {
        String[] names = {"Nokia","Samsung","Htc","Sony",
                          "Apple","Sony Ericsson","Philips",
                          "Toshiba","Micromax","Lenovo","Celkon",
                          "Casio","Acer"}; 
        JList jl = new JList(names);
        JScrollPane js = new JScrollPane(jl);
        js.setPreferredSize(new Dimension(200,200));
        add(js);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment