views:

342

answers:

1

Product Version: NetBeans IDE 6.8 (Build 200912041610) Java: 1.6.0_17; Java HotSpot(TM) Client VM 14.3-b01 System: Windows 7 version 6.1 running on x86; Cp1252; en_GB (nb)

Hello, newbee java programmer here and wondering if someone can help, I have been having some problems updating a GUI for a desktop application in netbeans, here are the details:


my current application GUI works great, everything is appearing correctly.

when I update the GUI by adding a new label from the netbeans toolbox onto my form, and use the netbeans preview function, everything looks great

however when i run the application the new label has disappeared..

to try and understand the problem i ran the app in debug mode and stepped through the auto-generated initComponents() code

from debugging i believe the problem comes from this line of code:

TEST_lbl.setText(resourceMap.getString("TEST_lbl.text")); // NOI18N

after this line of code has executed TEST_lbl.setText is equal to null..

so the label is disappearing when i run the app because it has no text value to display...

i opened the resource map file in notepad (the .properties file) and it contains an entry "TEST_lbl.text=jLabel1" among the entries for all the other working controls...

so the properties file has the correct value, but resourceMap.getString is not retrieving it

i can work around this problem by changing the "Automatic Resource Management" option of the form from "All Resources" to "Off"

as a result this changes the auto-generated "setText" code line to:

TEST_lbl.setText("jLabel1"); 

and makes the label display correctly when the application runs


my first question would be, is this a known bug? or have i done something silly and accidently changed a setting someware?

if this is not a bug, how do i correct the problem without changing the resource management setting?

if this is a bug, what are the implications of turning off automatic resource management?

Thanks for the help, - Gaz

A: 

I assume you're running it under NB (Run > Run Main Project)?

Try a clean build (Run > Clean and Build Main Project). That will usually fix it.

It's an issue of how the build system is structured.

When you run the project in a clean repository (Run > Run Main Project):

  1. the .class files are written to $project/build/classes
  2. the non-class files are copied into the tree
  3. the whole thing is run from there.

That works fine.

If you "build" the project (Run > Build Main Project): 1. the .class files are written to $project/build/classes 2. the non-class files are copied into the tree 3. the whole thing rolled up into a jar file.

That also works fine.

However, if you subsequently make changes and run the project, the class files and resources now appear in 2 places:

  • in build/classes
  • in the dist/project.jar

This works OK as far as finding class files. Resources, however, are found in the jar first. So, at runtime, you code finds the outdated copy of the properties file in the jar, not the new one in the filesystem.

Also: NB ignores case when finding a resource, but Sun's JVM does not (not sure about IcedTea). So, if the wrong case is used NB may insist the file is there, but the JVM will not be able to find it.

Devon_C_Miller
Your right, when i was initially digging around i noticed the properties file in the src directory, not realising there was also a second properties file in the build directory.and yes they only sync up when a clean operation is performed, everything is working well after a clean and i can turn on resource management again.thanks for the insightful reply, much appreciatedto benefit other users: if your labels are disappearing, buttons are shrinking or becoming flattened, or controls are not retaining their settings like text values, then it is likely you have a similar problem.
Gaz