-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLists.java
More file actions
69 lines (46 loc) · 1.57 KB
/
Lists.java
File metadata and controls
69 lines (46 loc) · 1.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package GUI;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
public class Lists extends JFrame {
private JPanel jPanel;
private JList jList;
private JLabel jLabel;
private JTextField jTextField;
public Lists() throws HeadlessException {
setTitle("list practice");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
build();
add(jPanel);
setSize(300,300);
setVisible(true);
}
public void build(){
String[] name = {"baba" , "mama" , "bement" , "hilina"};
jList = new JList(name);
jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jLabel = new JLabel("you select:");
jTextField = new JTextField(10);
jTextField.setEditable(false);
jList.addListSelectionListener(new l());
jList.setBackground(Color.decode("#fe3c12"));
jList.setBorder(BorderFactory.createLineBorder(Color.YELLOW,5));
jList.setVisibleRowCount(2);
JScrollPane jScrollPane = new JScrollPane(jList);
jPanel = new JPanel();
jPanel.add(jScrollPane);
jPanel.add(jLabel);
jPanel.add(jTextField);
}
private class l implements ListSelectionListener{
public void valueChanged(ListSelectionEvent e){
String in = (String)jList.getSelectedValue();
jTextField.setText(in);
}
}
public static void main(String[] args) {
new Lists();
}
}