Issue
Typically, a project layout is that src/main/java
contains the .java
files and src/main/resources
contains the resources. Thus, the *.form
files should to into resources
. However, NetBeans does not find them.
Is it possible to have NetBeans load the corresponding .form file from a different folder?
Maybe, I understood src/main/java
wrong and .form
should also go in there?!
Same folder
Different folders
Solution
What is the .form file
From faq:
The .form file is an XML file that the visual editor uses to store the information about the GUI form. It is much more reliable than reading the information from the source code. You do not need to distribute the .form file with your application; it's only used by the IDE. However, if you want to open your form again in the form editor, you should keep the file
Directory Layout
Indeed the standard directory layout for a maven project consists of src/main/java
for java files and src/main/resources
for resources. But it is only true for maven projects.
The ant-based project uses a different layout and usually places properties files and other files withing source directories but could use any custom locations for resources including sub-directories within a package.
Use a different folder for .forms files
Unfortunately, it's impossible to separate them from the relevant so caled "brother" files, see below. They are too tightly coupled together. For example, if you look at the project tree view NetBeans hides the .form files if there are relevant java files within the same directory.
Let's see the source code, precisely a method findPrimaryFile
that is used for finding a primary file:
protected FileObject findPrimaryFile(FileObject fo) {
if (fo.isFolder()) return null;
String ext = fo.getExt();
if (ext.equals(FORM_EXTENSION))
return FileUtil.findBrother(fo, JAVA_EXTENSION);
FileObject javaFile = findJavaPrimaryFile(fo);
return javaFile != null
&& FileUtil.findBrother(javaFile, FORM_EXTENSION) != null ?
javaFile : null;
}
It calls findBrother
method that looks for appropriate .form
or java
files and it always looks for the "brother" file within the same directory:
public static FileObject findBrother(FileObject fo, String ext) {
if (fo == null) {
return null;
}
FileObject parent = fo.getParent();
if (parent == null) {
return null;
}
return parent.getFileObject(fo.getName(), ext);
}
Answered By - Dmitry.M
Answer Checked By - Cary Denson (JavaFixing Admin)