BufferedImage (@NotNull JTree tree, @NotNull ArrayList<DragImageRow> dragImageRows) { var totalHeight = 0; var maxWidth = 0; for (var row : dragImageRows) { var size = row.getSize(); maxWidth = Math.max(maxWidth, size.width); totalHeight += size.height; } var gc = tree.getGraphicsConfiguration(); BufferedImage image = ImageUtil.createImage(gc, maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D)image.getGraphics(); try { for (var row : dragImageRows) { row.paint(g); g.translate(0, row.getSize().height); } } finally { g.dispose(); } return image; }