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.
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
Priority is changed to P4 (normal).
verified in [nb31](34), [boston](1160)
Resolved for 3.4.x or earlier, no new info since then -> closing.