}
} else {
throw new IllegalArgumentException("Component can only be JTable or JViewport holding JTable"); // NOI18N
}
final JTableHeader tableHeader = table.getTableHeader();
Dimension tableHeaderSize = tableHeader.getSize();
BufferedImage tableScreenshot = new BufferedImage(sourceSize.width, tableHeaderSize.height + sourceSize.height,
BufferedImage.TYPE_INT_RGB);
final Graphics tableScreenshotGraphics = tableScreenshot.getGraphics();
// Component.printAll has to run in AWT Thread to print component contents correctly
if (SwingUtilities.isEventDispatchThread()) {
tableHeader.printAll(tableScreenshotGraphics);
} else {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
tableHeader.printAll(tableScreenshotGraphics);
}
});
} catch (Exception e) {
}
}