Java Code
import javax.swing.*;
import java.awt.*;
public class JListExImage extends JApplet
{
DefaultListModel model;
JList majors;
Image img;
ImageIcon icon;
public void init( )
{
model = new DefaultListModel( );
majors = new JList( model );
img = getImage(getCodeBase( ), "buttonPoland.png");
icon = new ImageIcon( img );
model.add( 0, icon );
model.add( 1, "Europe" );
img = getImage( getCodeBase( ), "buttonLaos.png");
icon = new ImageIcon( img );
model.add( 2, icon );
model.add( 3, "Asia" );
img = getImage( getCodeBase( ), "buttonGirl.png" );
icon = new ImageIcon( img );
model.add( 4, icon );
setLayout( new FlowLayout( ) );
majors.setVisibleRowCount( 3 );
JScrollPane spane = new JScrollPane( majors );
add( spane );
}
}
Back to Code Examples
©2006-
by E.S.Boese. All Rights Reserved