CONSTRUCTORS OF JLIST IN JAVA:
JList(ListModel)
This constructor creates a jlist with specified elements/Non null elements.
This constructor creates a jlist with specified elements/Non null elements.
JList(Object[])
This constructor is used to create jlist with a specified array.
JList(Vector)
This constructor can only create a jlist with read only model for the given vector.
JList()
This constructor creates a empty jlist.
CODING:
import javax.swing.*;import java.awt.*;
class myfram extends JFrame
{
myfram()
{
setTitle("Simple Jlist");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] names = {"Item 1A","Item 1B","Item 1C","Item 1D","Item 1E","Item 1F","Item 1G"};
JList l1 = new JList(names);
JScrollPane lS = new JScrollPane(l1);
lS.setPreferredSize(new Dimension(300,100));
add(lS);
setSize(700,500);
setVisible(true);
}
}
public class simplelist
{
public static void main(String[] args) {
myfram fr = new myfram();
}
}
0 comments:
Post a Comment