forked from stiers/COPRO2_SampleJavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
JListDemo.java
45 lines (27 loc) · 875 Bytes
/
JListDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.awt.*;
import javax.swing.*;
public class JListDemo {
JList list;
String listColorNames[] = { "White", "Blue" };
Color listColorValues[] = { Color.WHITE, Color.BLUE };
public JListDemo() {
super( "List Source Demo" );
Container con = getContentPane();
con.setLayout( new FlowLayout() );
list = new JList( listColorNames );
list.selectedIndex( 0 );
list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
con.add( new JScrollPane( list ) );
list.addListSelectionListener( new ListSelectionListener() {
public void valueChanged( ListSelectionEvent e ) {
setBackground( listColorValues[list.getSelectedIndex()] );
}
} );
setSize( 200, 200 );
setVisible( true );
}
public static void main( String args[] ) {
JListDemo test = new JListDemo();
test.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}