Add JList into JFrame

Source code below will show you, how to create a list in java using JList. After that we will add it, into a jframe.

**************************************************************************
COMPLETE SOURCE CODE FOR : AddJListIntoJFrame.java
**************************************************************************


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class AddJListIntoJFrame
{
public static void main(String[]args)
{
//Create contents for JList
String[]listContents={"Honda","Toyota","Ford","Ferrari","Cooper"};

//Create a JList with it contents
JList myList=new JList(listContents);

//Create a JFrame with title ( Add JList into JFrame )
JFrame frame=new JFrame("Add JList into JFrame");

//Set layout for JFrame
frame.setLayout(new FlowLayout());

//Add JList into JFrame
frame.add(myList);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(400,400);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


**************************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************************