Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to populate JTable from ArrayList.I am getting values in ArrayList but unable to populate in Jtable.Any help would be appreciated.Below is my Code:
MongoClient mongo = new MongoClient("localhost", 27017);
			DB db = mongo.getDB("airlinedb");
		    DBCollection collection = db.getCollection("airlinefinal");
		    
		    BasicDBObject searchQuery = new BasicDBObject("ORIGIN","JFK");
		    BasicDBObject fields = new BasicDBObject();
		    fields.put("ORIGIN",1);
		    fields.put("DEST", 1);
		    fields.put("_id", 0);
		    DBCursor cursor = collection.find(searchQuery,fields);
		    
		    @SuppressWarnings("unused")
			List<DBObject> myList = new ArrayList<DBObject>();
		    myList = cursor.toArray();

String[] columnNames = {"Origin", "Destination"};
DefaultTableModel model = new DefaultTableModel(MyList, columnNames);
table = new JTable(model);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900