473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Dynamically Setting object name in java

I have a map of names and value.
I want to iterate over the map and set the key name as Jlabel Object Name and value as the Label name.

Below is the key map.
Expand|Select|Wrap|Line Numbers
  1.         fieldNames.put("empname","Employee Name");
  2.         fieldNames.put("empphn1","Phone number1");
  3.         fieldNames.put("empphn2","Phone number2");
  4.         fieldNames.put("empphn3","Phone number3");
  5.         fieldNames.put("addrs","Address");
  6.         fieldNames.put("slry" ,"Salary");
  7.         for (int count=0; count < fieldNames.entrySet().size(); count++){
  8.         String key=fieldNames.entrySet().iterator().next().getKey();
  9. //       new Jlabel().setID("lbl_"+key);
  10. //       new Jlabel().setName(fieldNames.get(key));
  11.  
  12.  
  13.  
Is there any way to set like above in java
Feb 7 '15 #1
1 1424
chaarmann
785 Expert 512MB
You are iterating in a wrong way.
Corrected code:
Expand|Select|Wrap|Line Numbers
  1. for (Iterator it = fieldNames.keySet().iterator(); it.hasNext();) {
  2.         String key = (String) it.next();
  3. //       new Jlabel().setID("lbl_"+key);
  4. //       new Jlabel().setName(fieldNames.get(key));
  5. }
Feb 11 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+...
3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
2
by: Jacques Leclerc | last post by:
What's the trick to dynamically setting the width of a textbox? In the code behind page Page_Load function I'm trying to dynamically set the width of a textbox. TextBox1.Width = "75px" I...
3
by: TheLostLeaf | last post by:
I am trying to dynamically create the object name..... but i can't get it to work... >From This (works) ------------------------------------------------------------------ label1.Text =...
2
by: RSH | last post by:
How do I go about creating an object name in a loop? I have a class named objSample Dim j As Integer For j = 1 To 10 Dim inpFile As System.Web.UI.HtmlControls.HtmlInputFile =
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
2
by: chris fellows | last post by:
In VS2005 (C#) I want to set the properties of an object dynamically at runtime from an XML configuration file but without having to know the property name when writing the code. The properties are...
3
by: gaya3 | last post by:
Hi, How to retreive String Object name from its value in java.? in the following example String s1="name"; Thanks in Advance -Thanks & Regards Hamsa
3
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, Is there a way to dynamically get the name of the current Sub? In my code below in the exception "catch" i write the name of the Sub to the error log so that i will know where there error...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.