-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComboBox.java
More file actions
82 lines (49 loc) · 1.65 KB
/
ComboBox.java
File metadata and controls
82 lines (49 loc) · 1.65 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
70
71
72
73
74
75
76
77
78
79
80
81
82
package GUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ComboBox extends JFrame {
private JPanel jPanel;
private JPanel main;
private JPanel j;
private JLabel jLabel;
private JTextField jTextField;
private JComboBox jComboBox;
public ComboBox(){
setTitle("combo box demo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
build();
j = new JPanel();
j.setLayout(new BorderLayout());
j.add(main,BorderLayout.CENTER);
j.add(jPanel,BorderLayout.SOUTH);
add(j);
pack();
setVisible(true);
}
public void build(){
String[] coffee = {"Regular coffee","Dark roast","Cappuccino","Espresso","Decaf"};
ImageIcon imageIcon = new ImageIcon("C:\\Users\\Bem\\Desktop\\New folder\\Telegram\\IMG_20220614_091608_230.jpg");
jLabel = new JLabel("You selected:",imageIcon,SwingConstants.LEFT);
jTextField = new JTextField(10);
jTextField.setEditable(false);
jComboBox = new JComboBox(coffee);
jComboBox.setEditable(true);
jComboBox.addActionListener(new al());
jPanel = new JPanel();
main = new JPanel();
main.add(jComboBox);
jPanel.add(jLabel);
jPanel.add(jTextField);
}
private class al implements ActionListener{
public void actionPerformed(ActionEvent e){
String selected = (String) jComboBox.getSelectedItem();
jTextField.setText(selected);
}
}
public static void main(String[] args) {
new ComboBox();
}
}