I am trying to populate a jtable from the data I get using mongoDB,this is the code i have:
JButton btnLista = new JButton("Listado");
btnLista.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
MongoClient conexion = new MongoClient("localhost", 27017);
DB base = conexion.getDB("dbunidad5");
DBCollection tabla = base.getCollection("vehiculos");
DBCursor cursor = tabla.find();
String[] columns = {"matricula","marca","modelo","precio"};
DefaultTableModel model = new DefaultTableModel(columns,0);
while (cursor.hasNext()) {
DBObject obj = cursor.next();
String matricula = (String)obj.get("matricula");
String marca = (String)obj.get("marca");
String modelo = (String)obj.get("modelo");
String precio = (String)obj.get("precio").toString();
model.addRow(new Object[] {matricula,marca,modelo,precio});
}
tblVehiculos = new JTable();
tblVehiculos.setVisible(true);
cursor.close();
conexion.close();
}
});
It doesnt`t give me any error but the table with the data doesnt show up. Can anyone help me and tell me what i´m doing wrong?
Thanks