File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes java applet print Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "java applet print" Watch "java applet print" New topic
Author

java applet print

rahul dwivedi
Greenhorn

Joined: Mar 01, 2005
Posts: 1
hi,
i have created a graph on the applet. now i want to take the printout of this graph. i am using one code but the problem tht is coming is that i am getting onlt legends in my print out, nothing else.


public class GraphApplet extends Applet implements MouseListener, ActionListener{

G2Dint graph;
JPanel panel = new JPanel();
JPanel buttonPanel = new JPanel();
JPanel checkboxPanel = new JPanel(new GridLayout(10,1));
JPanel legendPanel = new JPanel(new GridLayout(2,4));
------------

public void init()
{

graph = new G2Dint(); /* the object of the main G2Dint class which is responsible for the basic structure of the graph*/
panel.setBackground(new Color(127,127,127));
graph.setBackground(new Color(127,127,127));


panel.setLayout(new BorderLayout());
this.setLayout(blayout);
this.add(panel,BorderLayout.CENTER);
this.add(buttonPanel, BorderLayout.NORTH) ;
this.add(checkboxPanel, BorderLayout.WEST);
this.add(legendPanel, BorderLayout.SOUTH);
panel.add(graph,BorderLayout.CENTER);
}



public void mouseClicked(MouseEvent e)
{
Object object = e.getSource();
System.out.println("object -->"+object);
if (object == print)
{
System.out.println("PRINT Graph Panel :-->" + panel.getName());
System.out.println("PRINT Graph Panel :-->" + panel.toString());
//PrintUtilities sp = new PrintUtilities(this);
PrintUtilities.printComponent(panel);

}
}
}
class PrintUtilities implements Printable {
private Component componentToBePrinted;

public static void printComponent(Component c) {
new PrintUtilities(c).print();
}

public PrintUtilities(Component componentToBePrinted) {
System.out.println("INSIDE THE CONSTRUCTOR!!!" + componentToBePrinted);
System.out.println("componentToBePrinted getName:" + componentToBePrinted.getName());
System.out.println("componentToBePrinted toString:" + componentToBePrinted.toString());
this.componentToBePrinted = componentToBePrinted;
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
aset.add(new Copies(1));
aset.add(new JobName("My job", null));

PrintService[] services =
PrintServiceLookup.lookupPrintServices(flavor, aset);

System.out.println("Printer found :" + services);

}

public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}

public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}
}


public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}

/** Re-enables double buffering globally. */

public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java applet print
 
Similar Threads
Print Preview in Java swing
Printing TextArea which span more than 1 page
Printing
Help Printing in Landscape form
Print a JTextArea