20. januar 2005 - 15:06Der er
3 kommentarer og 1 løsning
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.
// 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; }
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
public void print(int orientation) throws PrinterException { // Get the PrinterJob object PrinterJob job = PrinterJob.getPrinterJob(); job.setJobName("Hydro Problem Tracking");
// Get the default page format, then allow the user to modify it //PageFormat format = job.pageDialog(job.defaultPage()); PageFormat format = new PageFormat(); format.setOrientation(orientation); c.setBackground(Color.WHITE);
// Configure the paper Paper paper = new Paper(); paper.setSize(2479, 3508); //A4PRT300 = new Dimension(2479, 3508); paper.setImageableArea(75,50,2375,3450);
// Sets the format to reflect the paper format.setPaper(paper); format = job.validatePage(format);
// Tell the PrinterJob what to print job.setPrintable(this, format);
// Ask the user to confirm, and then begin the printing process if (job.printDialog()) { job.print(); }
c.setBackground(Color.GRAY); }
Forskellen er c.setBackground(Color.WHITE);
Baggrunden er stadig "Grå" men teksten er nu sort.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.