private static void paintAndDispose(Graphics2D g, Consumer<? super Graphics2D> painter) {
    try {
      painter.accept(g);
    }
    finally {
      g.dispose();
    }
  }
private static void paintAndDispose(Graphics2D g, Consumer<? super Graphics2D> painter)