print content of JEditorPane

G

GALZ

hello

I am trying to print the content of a JEditorPane with this class. The
problem I have is the printer no prints the content of the MyEditorPane, it
only prints a diagonal line (because the program has a
g.drawLine(0,0,100,100); instruction)

Any idea?

Thanks!

Here is MyEditorPane class:


import java.awt.geom.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterJob;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

public class MyEditorPane extends JEditorPane implements Printable
{



public MyEditorPane() {
super();
}

public void imprimir()
{
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}





public void paintComponent(Graphics g)
{
System.out.println("paintComponent "+g);
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g = (Graphics2D) getComponentGraphics(g2);
g.drawLine(0,0,100,100);
}





public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}

g = (Graphics2D) getComponentGraphics(g);
g.drawLine(0,0,100,100);
return Printable.PAGE_EXISTS;
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top