Populate a JTable with the contents of a Map

420 views Asked by At

First I’d like to congratulate assylias on the amazing JBloomberg API that has saved my life and I'm asking how can I put the data that I get from the map in JTable already designed in Netbeans.

Here is the code for the historical prices:

Map<DateTime, TypedObject> data = result.forSecurity("SPX Index")
     .forField("PX_LAST").get();
for (Map.Entry<DateTime, TypedObject> e : data.entrySet()) {
    DateTime dt = e.getKey();
    double price = e.getValue().asDouble();
    System.out.println("[" + dt + "] " + price);
}

How could I place the content of the Map in a JTable?

2

There are 2 answers

0
malmo On

code

BloombergSession session = new DefaultBloombergSession();
session.start();
RequestBuilder<HistoricalData> hrb = new HistoricalRequestBuilder("SPX Index",
     "PX_LAST", DateTime.now().minusDays(7), DateTime.now()).fill(
     HistoricalRequestBuilder.Fill.NIL_VALUE).days(
     HistoricalRequestBuilder.Days.ALL_CALENDAR_DAYS);
HistoricalData result = session.submit(hrb).get();
Map<DateTime, TypedObject> data = result.forSecurity("SPX Index")
     .forField("PX_LAST").get();
for (Map.Entry<DateTime, TypedObject> e : data.entrySet()) {
    DateTime dt = e.getKey();
    double price = e.getValue().asDouble();
    System.out.println("[" + dt + "] " + price);
}
0
trashgod On

Wrap your Map<DateTime, TypedObject> in a TableModel, as shown in EnvTableTest.