| Author |
use of setLabelFor()
|
mani senthil
Greenhorn
Joined: Jan 18, 2007
Posts: 17
|
|
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
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8434
|
|
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.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
|
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.
|
 |
 |
|
|
subject: use of setLabelFor()
|
|
|