Skip to content

Instantly share code, notes, and snippets.

@wcmatthysen
Created February 19, 2020 11:08
Show Gist options
  • Save wcmatthysen/cb107a149e1f6888170a4e3afda15bc8 to your computer and use it in GitHub Desktop.
Save wcmatthysen/cb107a149e1f6888170a4e3afda15bc8 to your computer and use it in GitHub Desktop.
Set heavyweight tooltip popups for any component in Swing.
public final class ComponentUtils {
private ComponentUtils() { }
public static void forceHeavyWeightPopups(JComponent component) {
try {
Class<?> clazz = Class.forName("javax.swing.ClientPropertyKey");
Field field = clazz.getDeclaredField("PopupFactory_FORCE_HEAVYWEIGHT_POPUP");
field.setAccessible(true);
component.putClientProperty(field.get(null), Boolean.TRUE);
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) {
throw new RuntimeException("Couldn't force heavyweight popups on component: " + component, e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment