I'm just starting to learn about printing with Java Swing, so please bear with me if this question is very naive.
I have a rather complex layout with multiple JPanels that contain other JPanels that contain JLabels. I want somehow to print this nicely on a printer.
I know that I can "paint" on a Graphics2D object that represents a printed page, but that requires me to position each object individually. I would like to be able to use the Swing layout managers to layout the items on my page. One way to do this is to call jp.paint(g2d)
, where jp is a JPanel and g2d is the Graphics2D object representing the printed page. However, as far as I can see, this will only print a JPanel that is actually visible on the screen. If the JPanel is not visible, it will not be printed.
So is there any way to layout a (rather complex) JPanel and send it to a printer without first displaying the JPanel on the computer screen?
Or am I on a totally wrong track here?