Java Code

/** Example showing use of JList with add method
  * @author : E.S.Boese (c) Fall 2005
  */  
import javax.swing.*; 
import java.awt.*; 
public class JListEx extends JApplet 
{ 	
   DefaultListModel model;
   JList majors; 	
   public void init( ) 
   { 
		model = new DefaultListModel( );
		majors = new JList( model ); 	

		model.add( 0, "CS" ); 
		model.add( 1, "Math" ); 
		model.add( 2, "History" ); 
		model.add( 3, "Leisure Studies" ); 
		model.add( 4, "Psych" ); 
	
		setLayout( new FlowLayout( ) ); 
		add( majors );
    }
 } 

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