• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Use of jLabel name

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a method which is passed a String.
I wanted to use that String as the name of a component ( a jLabel ) so that I can do, if the string is "hello",

Is this possible? and if so how?
Cheers
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is possible.
e.g.
public void nameLabel(String s)
{
JLabel label = new JLabel(s);
}
and u call the method as: nameLabel("Hello");
[ May 11, 2004: Message edited by: Deboleena Chakraborty ]
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name of each widget (e.g. a JLabel) is set by the compiler and I can't see how you can change that during runtime. However, I can see a couple of avenues to label your widgets if there are a lot of them.
Firstly, you could do an array of widgets, and equate the int element to a name. Then write a method to search the name strings for the array numbers.
Secondly, without using an array, you could set up a map of key/value pairs with the key being the name and the value being the widget. Then write a method to return the widget on imputting a name.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic