Java Code

/** Example showing use of JList with addElement method
  * @author : E.S.Boese (c) Fall 2005
  */  
import javax.swing.*;
import java.awt.*;
public class JListWithAddElement extends JApplet
{
   DefaultListModel model;
   JList majors;
	
   public void init( )
   {
		model = new DefaultListModel( );
		majors = new JList( model );
		model.addElement( "CS" );
		model.addElement( "Math" );
		model.addElement( "History" );
		model.addElement( "Leisure Studies" );
		model.addElement( "Psych" );

		setLayout( new FlowLayout( ) );
		add( majors );
   }
}

Back to Code Examples
©2006- by E.S.Boese. All Rights Reserved