private static @Nullable Image paintToImage(@NotNull JComponent comp) {
    Dimension size = comp.getSize();
    if (size.width < 1 || size.height < 1) return null;
    BufferedImage image = UIUtil.createImage(comp, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    UIUtil.useSafely(image.getGraphics(), comp::paint);
    return image;
  }
private static @Nullable Image paintToImage(@NotNull JComponent comp)