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 setLabelFor()  RSS feed

 
mani senthil
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of setLabelFor() property of jlabel. what is the purpose? i red the definition but i con't understand that.

The code is like

static String[] names = {"Arlo", "Cosmo", "Elmo", "Hugo","Jethro", "Laszlo", "Milo", "Nemo", "Otto", "Ringo", "Rocco", "Rollo"};
JLabel intro = new JLabel("The chosen name:");
final JLabel name = new JLabel(names[1]);
intro.setLabelFor(name);
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine a login dialog. You got a label saying "Username" and a text field where the user should input the username.
You would typically use the JLabel#setDisplayedMnemonic to define say 'U'. Then you would use JLabel#setLabelFor(userNameField).
After this, when the user hits Alt+U, the user name text field would gain the focus.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you normally wouldn't use a JLabel as the parameter (argument?) of this method as it is not something that usually wants to gain focus.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!