Why does JavaFX work differently outside NetBeans? - java

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!

Some possible reasons:
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.
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).
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.
(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.

Related

How to automatically clear the terminal after every code run in VS Code (No Code Runner, No modifying a Java file)

I'm interested in being able to automatically clear the terminal every time I run my code (Java program with a main method that may or may not have packages inside the file). Code Runner only runs single class Java files and doesn't work with Java files that have packages so I'm not interested in that.
At the momement I'm running all my Java files by clicking on the "Run and Debug" button in VS Code. I'm aware that I can manually clear the console using Command + K (Mac) but doing this for every run feels repetitive so I'm looking for a way to do this automatically. Every time I click that run and debug button I'd like for it to clear the console before running an code. Is there also anyway to show a run button that maps to VS Code's "Run and Debug Button (Similar to the way Code Runner does it by displaying a run/triangle icon (left a screenshot below). Currently I have to make two clicks in order to click "Run and Debug".
I'm only looking for a solution that doesn't involve changing any Java files so something that involves changing settings/using an extension/related on VS code. I'm not looking to modify any Java file. Code Runner has the functionality I desire (clear terminal automatically) but doesn't work with all types of Java files so it again can't be used.
You could just put this line in your java file to clear the terminal.
For Windows:
Runtime.getRuntime().exec("cls");
For Linux:
Runtime.getRuntime().exec("clear");
If you can modify your output you can print an ANSI clear screen escape sequence before printing your first line of output.
System.out.println("\033[2J\033[1;1H");
Note, this will only work with VTE based terminals like Terminal.app, iTerm, almost all linux terminal emulators, Windows Powershell etc.

Just installed vim-javacomplete2 but doesn autocomplete at all

I am newbie to plugins in vim. I am using vim for a year but without any experience with plugins. So i installed Vim-plug, then add Plug vim-javacomplete2' to my .vimrc and :PlugInstall it. It was installed. Then I add autocmd FileType java setlocal omnifunc=javacomplete#Complete to my .vimrc as well - as is in github. But then, ther is nothing else. So some commands works. I Tried for example JCgenerateAccessors - which generate getter and setter upon my private fields. So commands works. But The autocompletation doesn (such main function). I am making classes within a file in my directory. Then javac Test.java and java Test - which runs it. But still, when editting in vim the Test.java, no autocompletation. What I did wrong?
Might a a bit late
<C-x><C-o> (ctrl + x,ctrl + o) will bring up a list of options.
Press this in insert mode wherever you would press ctrl + space in other IDEs
i.e.: after System.
Expanding upon #iaquobe's answer, autocompletion while typing or more specifically after the dot notation, isn't enabled by default with this plugin, unless triggered manually using C-x,C-o, which can -and will- become tedious over time.
There're other autocompletion plugins that can be installed along with other completion engines, and be configured to integrate with them, namely: vim-mucomplet, youcompleteme, and neocomplete.vim.

Make an executeble JAR run in a console when double clicked

I'm in the process of porting simple console apps written in C++ to Java in order to show how similar the languages are, and how code can be ported. I've exported executable JARs for the programs using Eclipse. These JARs work fine when they are run using the java -jar command. However, they do not run properly when executed from windows explorer (double clicked). A console window simply opens and closes rapidly.
The only solution I have found thus far is to use a batch file. Is there any other option?
There are some options:
Sleep a bit when the program is done, so you can read the output.
Call System.in.read() (again at the end of the program), which will wait until you type a char and hits enter.
Create your own little swing terminal, which doesn't close when the application code is done.
This seems like the jre used from the command line and from the registry are not the same (this can occur when multiple JRE's are installed)
Have you checked in your windows registry what is the jre used to run the executable jars ?
You can find more on the registry settings on sun's site
Seems to me that your main class does not even gets executed.
This would explain the quick open/close of console window.
Or is it possible that another program than java has the "jar" file type?
Happened to me after installing a Nokia software.
Using a batch file seems to be my best option. I suppose that's why Eclipse has a launcher.
Change the open with program to
c:\Program files\java\jre7\bin\javaw.exe

netbeans & java, resourceMap.getString returning null

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
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):
the .class files are written to $project/build/classes
the non-class files are copied into the tree
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.

How to launch multiple Java programs with one configuration on separate consoles (with Eclipse)

I'm working with a Java program that has multiple components (with Eclipse & Ant at the moment).
Is there some way to start multiple programs with one launch configuration? I have an Ant target that does the job (launches multiple programs) but there are things I would like to do:
I would like to debug the programs with Eclipse, hence the need for Eclipse launch.
I would like to see the outputs for the programs at separate consoles.
Also other ways to launch multiple Java programs "with one click" with separate consoles and/or debugging would be ok.
['multiple launch part':]
If you have an ant launch configuration which does what you want, you can always transform it into a java launcher calling ant.
Main Class: org.apache.tools.ant.Main
-Dant.home=${resource_loc:/myPath/apache_ant}
-f ${resource_loc:/myProject/config/myFile-ant.xml}
You can then launch this ant session as a regular java application, with all eclipse debugging facilities at your disposal.
Add to your classpath in the User Entries section (before your project and default path):
ant.jar
ant-launcher.jar
[Multiple console part]
May be a possible solution would be to make sure your ant launcher actually launches the different application in their own JVM process (one javaw.exe for each application)
That way, you could use the ability of the native eclipse console to switch between different process.
The Console view clearly separates output from each distinct "process" and keeps them in several "buffers". The Console has a built-in "switch" feature that will automatically switch the view to display the buffer of the last process that performed output, however you can easily switch the display to any "process buffer" you want to look at.
To switch the Console "buffer" display, just click on the black "Down arrow" next to the 4th toolbar button from the right in the Console View's title bar (the button
that resembles a computer screen):
this will show a pop-down menu listing the "names" of all active process buffers, preceded by an "order number".
The one currently displayed will have a check-mark before its "order number". You can switch the view to another display buffer simply by clicking on its name.
The question and selected answer here are both 6 years old.
Eclipse Launch Groups provides UI to run multiple launch configs. Launch Groups is apparently part of CDT but can be installed separately without CDT by installing "C/C++ Remote Launch" (org.eclipse.cdt.launch.remote).
There's actually a ticket opened at Eclipse site which requests this very same functionality. One of the contributors there proposed a plugin which allows grouping more launch configurations (possibly of different types) and start all of them with one mouse click.
Although the plugin functionality is limited, it does a great job. Source code is included so you can make changes as necessary. You will have to open it as a PDE project in your Eclipse and export it as a JAR, then place the JAR file in your Eclipse' plugins folder. A bit cumbersome but you do this only one time. After that restart your Eclipse and look for "Basic Workflow" in your launch configurations dialog.
Plugin source is available here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=39900#attach_177951

Categories

Resources