-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTablaGUI.java
More file actions
44 lines (35 loc) · 1.26 KB
/
TablaGUI.java
File metadata and controls
44 lines (35 loc) · 1.26 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
import javax.swing.*;
public class TablaGUI {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
crearTabla();
}
});
}
private static void crearTabla() {
// Creamos la ventana
// donde se colocaran los botones, tablas, etiquetas, etc.
JFrame frame = new JFrame("Mi primer Tabla en Java");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Crear una tabla
String[] columnas = { "Nombre", "Edad", "Genero" };
// Datos que llenaran la tabla
Object[][] datos = {
{ "Lupita", 26, "Femenino" },
{ "Alberto", 36, "Masculino" },
{ "Gabriel", 26, "Masculino" }
};
// Crear la tabla con la información.
JTable tabla = new JTable(datos, columnas);
// Agregamos la tabla a un JSCrollPane
JScrollPane scroll = new JScrollPane(tabla);
// tabla.setFillsViewPortHeight(true);
// Añadimos el JSCrollPane al frame.
frame.add(scroll);
// Poner un tamaño para esta ventana
// y además hacerlo visible.
frame.setSize(400, 200);
frame.setVisible(true);
}
}