This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
JVentanaConLista.java
93 lines (82 loc) · 2.75 KB
/
JVentanaConLista.java
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
83
84
85
86
87
88
89
90
91
92
93
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class JVentanaConLista extends JFrame {
private JPanel contentPane;
private JList list;
public JVentanaConLista() {
super("Probando un JList");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 337, 295);
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(0, 0, 331, 267);
contentPane.add(scrollPane);
list = new JList();
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
if (arg0.getClickCount() == 2) {
mostrarSeleccionDeLaLista((String) list.getSelectedValue());
}
}
});
DefaultListModel modelo = new DefaultListModel();
modelo.addElement("Rojo Claro");
modelo.addElement("Rojo Oscuro");
modelo.addElement("Verde Claro");
modelo.addElement("Verde Oscuro");
modelo.addElement("Marrón Claro");
modelo.addElement("Marrón Claro");
modelo.addElement("Azul");
modelo.addElement("Celeste");
modelo.addElement("Negro");
modelo.addElement("Violeta");
modelo.addElement("Rosa Claro");
modelo.addElement("Rosa Oscuro");
modelo.addElement("Naranja");
modelo.addElement("Blanco");
modelo.addElement("Amarillo");
modelo.addElement("Gris Claro");
modelo.addElement("Gris Oscuro");
list.setModel(modelo);
scrollPane.setViewportView(list);
setLocationRelativeTo(null);
}
public void mostrarSeleccionDeLaLista(String seleccionado) {
JOptionPane.showMessageDialog(this, seleccionado);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new JVentanaConLista().setVisible(true);
}
}