ScrollList.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.*;
16: import javax.swing.*;
17: import javax.swing.event.*;
18:
19: public class ScrollList extends JScrollPane {
20:
21: private DefaultListModel<String> listModel;
22: private JList<String> list;
23:
24: @SuppressWarnings ("this-escape") public ScrollList (DefaultListModel<String> listModel) {
25: super ();
26: this.listModel = listModel;
27: list = new JList<String> (listModel);
28: setViewportView (list);
29: }
30:
31: public Color getBackground () {
32: return list == null ? null : list.getBackground ();
33: }
34: public void setBackground (Color background) {
35: super.setBackground (background);
36: if (list != null) {
37: list.setBackground (background);
38: }
39: }
40:
41: public Color getForeground () {
42: return list == null ? null : list.getForeground ();
43: }
44: public void setForeground (Color foreground) {
45: super.setForeground (foreground);
46: if (list != null) {
47: list.setForeground (foreground);
48: }
49: }
50:
51: public Font getFont () {
52: return list == null ? null : list.getFont ();
53: }
54: public void setFont (Font font) {
55: super.setFont (font);
56: if (list != null) {
57: list.setFont (font);
58: }
59: }
60:
61: public int getVisibleRowCount () {
62: return list == null ? 8 : list.getVisibleRowCount ();
63: }
64: public void setVisibleRowCount (int visibleRowCount) {
65: if (list != null) {
66: list.setVisibleRowCount (visibleRowCount);
67: }
68: }
69:
70: public int getSelectedIndex () {
71: return list == null ? -1 : list.getSelectedIndex ();
72: }
73: public void setSelectedIndex (int selectedIndex) {
74: if (list != null) {
75: list.setSelectedIndex (selectedIndex);
76: }
77: }
78:
79: public int[] getSelectedIndices () {
80: return list == null ? new int[0] : list.getSelectedIndices ();
81: }
82: public void setSelectedIndices (int selectedIndices[]) {
83: if (list != null) {
84: list.setSelectedIndices (selectedIndices);
85: }
86: }
87:
88: public int getSelectionMode () {
89: return list == null ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : list.getSelectionMode ();
90: }
91: public void setSelectionMode (int selectionMode) {
92: if (list != null) {
93: list.setSelectionMode (selectionMode);
94: }
95: }
96:
97: public void addListSelectionListener (ListSelectionListener listener) {
98: list.addListSelectionListener (listener);
99: }
100: public ListSelectionListener[] getListSelectionListeners () {
101: return list.getListSelectionListeners ();
102: }
103: public void removeListSelectionListener (ListSelectionListener listener) {
104: list.removeListSelectionListener (listener);
105: }
106:
107: public void setTexts (String[] texts) {
108: listModel.clear ();
109: for (String text : texts) {
110: listModel.addElement (text);
111: }
112: }
113: public void addElement (String element) {
114: listModel.addElement (element);
115: }
116: public void clear () {
117: listModel.clear ();
118: }
119:
120: }
121:
122:
123: