The issue pops up when you resize the desktop, as is commonplace when you use VNC across multiple machines.
A good workaround for this issue is to install the latest Oracle Java 8.
If you are using Ubuntu, you can add the Oracle 8 ppa:
sudo add-apt-repository ppa:webupd8team/java
sudo apt update
sudo apt install oracle-java8-installer
Once you have installed Java 8, we can now override the Java version that MATLAB uses. The following procedure is based on this MATLAB Answers post.
We need to find the directory of the JRE. If you installed using the ppa, then this directory should be /usr/lib/jvm/java-8-oracle/jre
.
Otherwise, you need to look for the directory of the java installation such that in the subdirectory lib
, you can find the file rt.jar
.
As long as the environment variable MATLAB_JAVA
is set to that directory, you should be able to start MATLAB with the newer version of java.
In my case, I created a simple bash script that runs MATLAB with the environment variable set:
#!/bin/bash
MATLAB_JAVA="/usr/lib/jvm/java-8-oracle/jre" \
/usr/local/bin/matlab "$@"
You might have to change the location of the MATLAB executable. You should also make the file executable and optionally place it on your path.
When you run version -java
in MATLAB, it should return the same information as java -version
on the terminal, where java
is the executable that you just installed. (It might not be your selected java version.)