aspose file tools
The moose likes Swing / AWT / SWT and the fly likes use of setLabelFor() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "use of setLabelFor()" Watch "use of setLabelFor()" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: use of setLabelFor()
 
Similar Threads
jcombobox help
Not able to read the value of a component on one JPanel from a different JPanel
Set colon mnemonic key for JLabel
create dynamic checkboxes
Mouse shift event coding - to trigger a predetermined sequence of images to a GUI