Compiz and Java Problems, Solutions
- 21 de junho de 2008
If you use Java on desktop and keep Compiz active, you might encounter windows that turn grey, freeze or don’t respond properly. This happened to me using Zend Studio every day. With Compiz on, the window would open and stay completely grey. The fix is simple and works for other Java applications.
In Zend’s case, just edit the startup script and export a variable before the rest of the code. The file usually has a name like Zend_Development_Environment. Open it and add the line below right at the beginning:
vim ZendStudio-5.5.0/Zend_Development_Environment
export AWT_TOOLKIT=MToolkit
After saving, start the program again. Here it worked immediately and Compiz continued active without friction.
What’s happening behind the scenes is a clash between the graphics compositor and Java’s default window toolkit. By forcing the use of MToolkit, Java starts drawing in a way that’s more compatible with the composited environment and the visual artifacts disappear. The adjustment works for any Java app. If you prefer to apply it to just one program, create a simple wrapper:
#!/bin/bash
export AWT_TOOLKIT=MToolkit
java -jar myapp.jar
If you want all your Java programs to use this path, add to your ~/.bashrc or ~/.profile:
export AWT_TOOLKIT=MToolkit
You can also adjust a .desktop shortcut using env in Exec:
[Desktop Entry]
Name=My Java App
Exec=env AWT_TOOLKIT=MToolkit java -jar /path/to/app.jar
Icon=icon.png
Type=Application
If grey windows, unresponsive buttons or strange rendering still appear, close the app, confirm the variable was applied and try again. In stubborn cases, restart the graphics session. As an alternative, some combinations help in specific scenarios:
# Try GTK look and feel
export AWT_TOOLKIT=gtk
# Force Java 2D without problematic acceleration
export JAVA_2D_NODDRAW=true
export J2D_D3D=false
Or passing properties directly in execution:
java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dawt.toolkit=sun.awt.motif.MToolkit -jar application.jar
In distributions like Ubuntu, Fedora, openSUSE and Debian with active effects, this adjustment is usually sufficient for IDEs and tools like Eclipse, NetBeans, IntelliJ, Zend Studio, JDeveloper, plus editors and utilities in Java. The idea is simple: keep Compiz on and, at the same time, use your applications without headaches.