I have a HashMap<String, String>
representing a date (the key), and an amount (the value).
I would like to display this information on my interface. I began by using an ArrayList and adding a new JLabel to it for each new key & value that was added to the HashMap. However this led to display problems, and I also feel like it's not the right way to do this:
Iterator iterator = labels.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry pairs = (Map.Entry)iterator.next();
entries.add(new JLabel(pairs.getKey() + ": £" + pairs.getValue()));
for(JLabel entry : entries) {
mainPanel.add(entry);
for(int i = 0; i < entries.size() - 1; i+=2) {
JLabel labelOne = entries.get(i);
JLabel labelTwo = entries.get(i+1);
mainPanelLayout.putConstraint(SpringLayout.NORTH, labelOne,
400,
SpringLayout.NORTH, contentPane);
mainPanelLayout.putConstraint(SpringLayout.NORTH, labelTwo,
10,
SpringLayout.SOUTH, labelOne);
}
/*mainPanelLayout.putConstraint(SpringLayout.NORTH, entry,
400,
SpringLayout.NORTH, contentPane);*/
}
}
In terms of what I'm trying to achieve, I want to display the information like so:
21/04/13 : 300
22/04/13 : 400
Is there a way of displaying information from the HashMap
in GUI?