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 package org.ximtec.igesture.graphics;
28
29 import java.awt.Color;
30 import java.awt.Dimension;
31
32 import javax.swing.JList;
33 import javax.swing.JScrollPane;
34 import javax.swing.ListModel;
35 import javax.swing.border.LineBorder;
36
37
38
39
40
41
42
43
44
45 public class ScrollableList extends JScrollPane {
46
47 private JList list;
48
49
50 public ScrollableList(ListModel listModel, int width, int height) {
51 super();
52 setPreferredSize(new Dimension(width, height));
53 setAutoscrolls(true);
54
55 if (listModel == null) {
56 list = new JList();
57 }
58 else {
59 list = new JList(listModel);
60 }
61
62 list.setVisible(true);
63 list.setBorder(new LineBorder(Color.BLACK));
64 list.setAutoscrolls(true);
65 setViewportView(list);
66 }
67
68
69 public JList getList() {
70 return list;
71 }
72
73
74 public int getSelectedIndex() {
75 return list.getSelectedIndex();
76 }
77
78
79 public Object getSelectedValue() {
80 return list.getSelectedValue();
81 }
82
83
84 public void setModel(ListModel model) {
85 list.setModel(model);
86 }
87 }