Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeMap 2

Status
Not open for further replies.

ALongpwneage

Programmer
May 17, 2007
6
I am displaying the TreeMap in a gui interface, and i am trying to return both the current and previous keys, but it is only returning one. If anyone has a idea on how to return both it would be much appreciated. My code is below.


private void saveJButtonActionPerformed( ActionEvent event )
{

//Creates the tree map and the values that will be placed in the map
TreeMap hm = new TreeMap();
hm.put("Average Attendance ", subtotalJTextField.getText());
hm.put("1)",Name1JTextFeild.getText());
hm.put("Attendance", Members1JTextFeild.getText());
hm.put("2)",Name2JLabel.getText());
hm.put("Attendance", Members2JTextFeild.getText());
hm.put("3)",Name3JLabel.getText());
hm.put("Attendance", Members3JTextFeild.getText());
Set set = hm.entrySet();

Iterator i = set.iterator();


//displays the values in the map
while( i.hasNext())
{

Map.Entry me = (Map.Entry)i.next();
DisplayAttendance.setText(me.getKey() + " : " + me.getValue());
System.out.println(me.getKey() + " " + me.getValue());


}
 
Where are you trying to keep the previous key/value? Each loop, me is always the next entry. In order to display the previous one at the same iteration, you need to have saved it off in the previous iteration.

_________________
Bob Rashkin
 
something like:
oldString = me.getKey() + " " + me.getValue();
at the end of the loop?

_________________
Bob Rashkin
 
When you get the loop, you will only have the value for the third textfield.

Could you explain with more detais what are you trying to do?

Cheers,
Dian
 
Can you post what your are displaying?
Is it displaying 3 times or only once?

if you are trying to any particular entry, you should reference it with th correct index..

I second dian here, please be more specific about what you are trying to achieve..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top