Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of jLabel name  RSS feed

 
Graham King
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Deboleena Chakraborty
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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 ]
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!