Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display a HashMap item in a JLabel

 
Ian Locke
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Im trying to get a Customer to display in a JLabel after I enter its HashMap ID in a JTextField. I want it to appear after clicking a button to search for the ID. The name of the HashMap is:

mapCustomer = new HashMap<String, Customer>();

The button is in my addBooking JDialog.

Thanks
Ian


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to start, this will cause you much grief (mixing awt.Label with swing components)
this.add(new Label("Customer ID:"));

further reading
http://java.sun.com/products/jfc/tsc/articles/mixing/

change them all to swing.JLabel

is that the label you want the customer data in? (indicates for ID only)
if so, just make the label a class field (similar to the way you have declared the textfields)

or is the question related to getting the data from the HashMap?
if so, it's just
Customer cust = mapCustomer.get(custID);
theLabel.setText(cust.field1+[delimiter]+cust.field2+etc);
or you might want to consider a single row JTable (where you can also add the header)
 
Ian Locke
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Micheal Dunn

I got it working by getting the data from the hashmap.

Cheers
Ian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic