Problemas con JTable
Hola.
¿Como podrÃa insertar objetos de distinto tipo (int, boolean, etc) en un JTable?
A parte de eso, como puedo seleccionar una fila del JTable? Necesito algun boton, actionListener o algo asi?
Un saludo
¿Como podrÃa insertar objetos de distinto tipo (int, boolean, etc) en un JTable?
A parte de eso, como puedo seleccionar una fila del JTable? Necesito algun boton, actionListener o algo asi?
Un saludo
normalmente el JTable recibe un array de Objects, puedes hacer algo como
String[] title = {"Integer", "Boolean", "String"};
Object[][] obj = {{new Integer(35557), new Boolean(true), new String("nombre")}};
JTable table = new JTable(obj, title);
con esto creas una tabla con varios tipos, checa el API para ver los diferentes constructores,
Para oibtener algun valor en particular, puedes hacer
table.getModel().getValueAt(x, y); // devuelve un Object
y para cambiar un valor puedes hacer
table.getModel().setValueAt(myObject, x, y);
si quieres seleccionar una fila:
table.setRowSelectionInterval(renglonInicio, renglonFinal);
String[] title = {"Integer", "Boolean", "String"};
Object[][] obj = {{new Integer(35557), new Boolean(true), new String("nombre")}};
JTable table = new JTable(obj, title);
con esto creas una tabla con varios tipos, checa el API para ver los diferentes constructores,
Para oibtener algun valor en particular, puedes hacer
table.getModel().getValueAt(x, y); // devuelve un Object
y para cambiar un valor puedes hacer
table.getModel().setValueAt(myObject, x, y);
si quieres seleccionar una fila:
table.setRowSelectionInterval(renglonInicio, renglonFinal);
