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;
}
}
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;
}
}