J2SE Swing at printe
Jeg har en nydelig printe metode kørende. Jeg kan skrive hele framen ud, inkl- Billeder
- JLabel
- JTextField
- JTextArea
- DropDownBox
- nydelig "grå" baggrund. Et spg til senere.
Hvad jeg ikke får ud er:
- String værdierne fra de Fine JTextField rammer (JTextArea).
Hvad misser jeg?
Min callback print()
public int print(Graphics g, PageFormat format, int pagenum) {
// The PrinterJob will keep trying to print pages until we return
// this value to tell it that it has reached the end
getContentPane().setBackground(Color.WHITE);
if (pagenum > 0)
return Printable.NO_SUCH_PAGE;
// We're passed a Graphics object, but it can always be cast to Graphics2D
Graphics2D g2 = (Graphics2D) g;
// Use the top and left margins specified in the PageFormat Note
// that the PageFormat methods are poorly named. They specify
// margins, not the actual imageable area of the printer.
g2.translate(format.getImageableX(), format.getImageableY());
// Tell the Component to draw itself to the printer by passing in
// the Graphics2D object. This will not work well if the Component
// has double-buffering enabled.
paint(g2);
getContentPane().setBackground(Color.GRAY);
// Return this constant to tell the PrinterJob that we printed the page
return Printable.PAGE_EXISTS;
}