How I fixed Ubuntu Java blank / colored windows

Problem

On a libvirt VM running Ubuntu, you see blank or colored windows when running Java applications. In my case, the windows were pink and yellow but didnt’t show any content.

Solution

In my case, I had openjdk-11-jre installed. This is an extremely old version for Ubuntu 24.04, so:

sudo apt purge openjdk-11-jre
sudo apt install default-jre

In our case, default-jre is OpenJDK 21 aka openjdk-21-jre.

After that, I restarted the Java application and it ran fine.