BlackRainbow BlackRainbow - 2 years ago 69
Java Question

Why does JavaFX work differently outside NetBeans?

I made a Java application (JDK 1.7) using Netbeans 8.1 and JavaFX.

The basic idea is a grid filled with letters, the rows and columns are sequentially highlighted to allow a person to chose a letter with a single key press (spacebar). Once the number of characters is equal or greater than 3, I implemented an autocomplete feature that fetches word starting with those letters and ranks them by lexical frequency.

It works really well when I run the project from inside the IDE but when I try to run it outside the following happens:

  • when I start the program, input doesn't work for a long time (10-15 seconds... although sometimes it works almost instantly and sometimes it takes even more time)... but once it starts detecting my key presses again, it works 100% of the time. It's not limited to the spacebar (also "+" and "-" used to manipulate the speed of the highlighting). Also, the program isn't frozen, I can resize stuff just fine and the row/columns are animated.

  • I also put a label next to the row where I put my autocomplete suggestions. Said label is supposed to be tilted -90°. Whenever I run it from outside Netbeans, it loses its rotation. Note: I don't use a CSS file, I used .SetStyle().

How can it behave differently just because I don't run the application from Netbeans?

Thank you for your answer!

Answer Source

Some possible reasons:

  1. The .jar file is not up to date.

Netbeans runs from the .class files while running externally uses the .jar file.

Do a clean and rebuild and try again.

  1. Different classpath.

Netbeans specifies the classpath to all the libraries it wants the app to use on the command line. What command line are you using? Are there any differences?

You can see the command line used in the output window when Netbeans runs your app (you may need to enable a verbose form of output - with Maven you can add --debug).

  1. Security problems that take some time to resolve if you have reduced privileges.

Many people give Netbeans administrator rights (allows it to create jar files for example). This may not be the case on the command line.

Try running the .jar from a command prompt with admin rights.

  1. (Inspired by the actual problem - thank you @BlackRainbow) - The Netbeans project will be bound to a specific Java version. When run from the command line using just Java ... -jar ... you will get the latest Java version which may be different.

Try running it from the command line selecting a specific version of Java. Something like "C:\Program Files\Java\jdk7\jre\bin\java" ... or similar.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download