Printable demo : Print « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » 2D Graphics GUI » PrintScreenshots 
Printable demo
Printable demo


import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintableDemo implements Printable {
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    if (pageIndex != 0)
      return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2Dg;
    g2.setFont(new Font("Serif", Font.PLAIN, 36));
    g2.setPaint(Color.black);
    g2.drawString("Java Source and Support"100100);
    Rectangle2D outline = new Rectangle2D.Double(pf.getImageableX(), pf
        .getImageableY(), pf.getImageableWidth(), pf
        .getImageableHeight());
    g2.draw(outline);
    return PAGE_EXISTS;
  }
  public static void main(String[] args) {
    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = pj.defaultPage();
    Paper paper = new Paper();
    double margin = 36// half inch
    paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
        paper.getHeight() - margin * 2);
    pf.setPaper(paper);

    pj.setPrintable(new PrintableDemo(), pf);
    if (pj.printDialog()) {
      try {
        pj.print();
      catch (PrinterException e) {
        System.out.println(e);
      }
    }
  }
}

           
       
Related examples in the same category
1. Print an Image to print directly
2. Simplest SWT Print ExampleSimplest SWT Print Example
3. Print in Java 2: PrinterJob
4. Print in Java: page format and document
5. Print in Java: Multi page
6. Print in Java 5
7. Print in Java 6
8. Simple Book for printingSimple Book for printing
9. Shapes PrintShapes Print
10. Display the print dialog and print
11. Print the printable area outlinePrint the printable area outline
12. Print the text file and print preview themPrint the text file and print preview them
13. Print Swing componentsPrint Swing components
14. BookBook
15. Another print demoAnother print demo
16. Book demoBook demo
17. Printing the Combined-Java 1.2-and-1.4 WayPrinting the Combined-Java 1.2-and-1.4 Way
18. Printing the Java 1.4 Way
19. Prompting for a Printer
20. Printing the Java 1.1 WayPrinting the Java 1.1 Way
21. ScribbleScribble
22. Printable Document
23. PrintFile -- Print a file named on the command linePrintFile -- Print a file named on the command line
24. Print to the standard output
25. PrintPanel is the base for an open-ended series of classesPrintPanel is the base for an open-ended series of classes
26. Print Demo: BookPrint Demo: Book
27. Print Test Print Test
28. Pageable TextPageable Text
29. Printable Component
w_w_w__.___j___a__va__2___s___.c___o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.