assert SwingUtilities.isEventDispatchThread();
//need to have big value but smaller than MAX_VALUE otherwise
//printing goes south due to overflow somewhere
final int HUGE_INTEGER = Integer.MAX_VALUE - 1000;
CellRendererPane rendererPane = new CellRendererPane();
//need to use JViewport since text is layouted to the viewPort width
//otherwise it will be layouted to the maximum text width
JViewport viewport = new JViewport();
viewport.setBorder(null);
Dimension size = new Dimension(width, HUGE_INTEGER);
//JTextField is a special case
//it layouts text in the middle by Y
if (printShell instanceof JTextField) {
size =
new Dimension(size.width, printShell.getPreferredSize().height);
}
printShell.setSize(size);
viewport.setComponentOrientation(printShell.getComponentOrientation());
viewport.setSize(size);
viewport.add(printShell);
rendererPane.add(viewport);
}