-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.java
More file actions
34 lines (31 loc) · 918 Bytes
/
list.java
File metadata and controls
34 lines (31 loc) · 918 Bytes
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
package mayank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class list extends JFrame{
private JList list;
private String[] color={"white","black","red","green"};
private Color[] background={Color.WHITE,Color.BLACK,Color.RED,Color.GREEN};
list(){
super("the title");
setLayout(new FlowLayout());
list=new JList(color);
list.setVisibleRowCount(2);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(list));
list.addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
getContentPane().setBackground(background[list.getSelectedIndex()]);
}
}
);
}
public static void main(String[] args) {
list ob=new list();
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
ob.setSize(300,300);
}
}