permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes Display a HashMap item in a JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display a HashMap item in a JLabel" Watch "Display a HashMap item in a JLabel" New topic
Author

Display a HashMap item in a JLabel

Ian Locke
Greenhorn

Joined: Feb 26, 2009
Posts: 5
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 26, 2009
Posts: 5
Thanks Micheal Dunn

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

Cheers
Ian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display a HashMap item in a JLabel