|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
LabeledList.java | - | 0% | 0% | 0% |
|
1 |
package example;
|
|
2 |
|
|
3 |
import java.awt.*;
|
|
4 |
import javax.swing.*;
|
|
5 |
import javax.swing.event.*;
|
|
6 |
|
|
7 |
/** Source code for Tutorial 2. */
|
|
8 |
|
|
9 |
public class LabeledList extends JPanel { |
|
10 |
private JList list;
|
|
11 |
private JLabel label;
|
|
12 | 0 |
public LabeledList(String[] initialContents) {
|
13 | 0 |
setLayout(new BorderLayout());
|
14 | 0 |
list = new JList(initialContents);
|
15 | 0 |
add(list, BorderLayout.CENTER); |
16 | 0 |
label = new JLabel("Selected: "); |
17 | 0 |
add(label, BorderLayout.SOUTH); |
18 |
// Update the label whenever the list selection changes
|
|
19 | 0 |
list.addListSelectionListener(new ListSelectionListener() {
|
20 | 0 |
public void valueChanged(ListSelectionEvent lse) { |
21 | 0 |
label.setText("Selected: " + list.getSelectedValue());
|
22 |
} |
|
23 |
}); |
|
24 |
} |
|
25 |
} |
|
26 |
|
|