Studio 8.1 Variables created in forms is local to initComponents().
Hello
I upgraded to Studio 8.1, and with that rewritten some of the codes in my project, using forms. It worked nice until the variables created using form in one class became local to the initComponent() method. I cannot say what I did to deserve that, but code outside the method no longer have acces to the variables. In options I have several times chosen (from Options-Misc-GUI builder) "generate components as fields in the form class" (as opposed to "local variables in initComponent method") without any luck. New variables created in the form editor becomes local for that class. Other classes works as expected. So; how can I make variables accesible to methods outside initComponent method? (so the appear near bottom of source code).
Regard
Fluid
[783 byte] By [
Fluid] at [2007-11-26 11:27:44]

# 1
- Right-click on the form.
- Select properties.
- Set the 'variables modifier' to public.
The above method seems to generate 'public' variables for that form once you set it.
The option is also available in the general options dialog:
- tools | options
- editing | form editor settings
- 'variables modifier' property: set it to public.
But the change does not seem to take effect for currently open forms. You may want to close all the forms, set the ide-wide option in options dialog and then reopen the forms.
# 2
Well, this is strange.
No .form files are visible in either "Project" or "Files" tab. I only see them in windows explorer, so they are there for sure.
In options (advanced) there are no form editor settings under editing. Under "GUI editor" however I can check for "local" variables and set modifier. They are currently unchecked and public.
I have restarted the machine even to ensure the settings are picked up by the program. I have edited the .form files from within windows so that the presumably relevant section looks like:
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,1 10,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104 ,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>
I have shift-F11 compiled the source without any different.
I like to make clear I am using Studio 8.1, and that I am not interested in having the variables "public", but outside the initComponent() method so that they are accessible to other class-methods. This is the standard/usual setting as I know it.
But now I must also ask how I can display and open the .form files in Studio 8.1, as this seem to be possible.
Regards
Fluid
Fluid at 2007-7-7 3:43:22 >

# 4
Some general info:
The form editor faqs are available at:
http://wiki.netbeans.info/wiki/view/NetBeansUserFAQ
http://wiki.netbeans.info/wiki/view/FaqFormFormFile
You can also refer to form.netbeans.org for more information. JSE8 is based on NetBeans 4.1.
As to your questions, .form file is an xml representation of a GUI form and is not shown in the ide explorer views. From the ide's point of view, .java and its corresponding .form are the same entity and therefore only the java file itself is shown (but with relevant context menu actions as opposed to a regular java file). Thus the .form file itself cannot be directly edited in the ide. In fact the GUI builder in the ide is the one that edits the .form file; when components are dragged and dropped and otherwise edited in the gui editor, the underlying .form file is modified by the ide.
Regarding moving the variables outside initComponent, the only way is to set the 'local' variables option (either globally in tools | options dialog or locally in a form class's properties). But this should be done prior to adding any variables to the form because this setting only affects variables that are defined after the setting is made and does not change any existing variables. For existing variables, the only way is what you did: modify it outside. But for future projects, if you set the option just after creating the form, then the variables should be created as per the setting.