This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 4573 - jLabel`s setLabelFor is not generated correctly
Summary: jLabel`s setLabelFor is not generated correctly
Status: CLOSED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 3.x
Hardware: All All
: P4 normal (vote)
Assignee: _ tboudreau
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1999-10-25 19:19 UTC by _ tboudreau
Modified: 2003-07-02 15:41 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 1999-10-25 19:19:27 UTC
I`ve encountered a problem with the code generated for the `labelFor`

property of JLabel. This mail will be a little bit longer, because the problem
is not just wrong generated code. The possible solutions will need
discussion.

What I try to do: When you generate a form with labeled text fields you
can give the label a mnemonic and connect it with the text field. If the
mnemonic is activated the requestFocus method of the text field is called. (btw:
It would be nice if the mnemonic would be shown in the form window)
There is a small program attached to this mail that brings up a example
window with two label-text field-pairs. Pressing ALT-1 should set the cursor
in the first text field and pressing ALT-2 should set the cursor in the
second text field. If you uncomment the two lines in the constructor method this
works correct but the code generated by NetBeans does not work.

The Problem:
The label is in front of the text field. For this at the time the label is
generated (and the setLabelFor method is called) the text field is declared
but not instantiated and the parameter for setLabelFor is null.

Solutions:
1. (Not recommended)
Similar to the workaround in the test program it is possible to call the
setLabelFor methods at the very end of initComponents(). But this would tear

the code belonging to one component in two parts.
2. (Also not recommended)
The component initialization could be resorted to ensure the text field is
instantiated before the label. I`m not sure if this is possible in all
situations.
3. (My suggestion)
The components of a form are instantiated only once and every time at
startup. In this situation it would make nearly no difference to instantiate
them at declaration time. [Changing "private javax.swing.JTextField
jTextField1;" to "private javax.swing.JTextField jTextField1 = new
javax.swing.JTextField ();" in the variable declaration section and removing "jTextField1 = new
javax.swing.JTextField ();" in in
Comment 1 Marek Grummich 2000-07-25 09:27:59 UTC
Priority is changed to P4 (normal).
Comment 2 Marian Mirilovic 2001-01-17 15:37:59 UTC
verified in [nb31](34), [boston](1160)
Comment 3 Quality Engineering 2003-07-02 15:41:59 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.