| | |
Printing in awt
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
I want to know how to print the contents of the text area including all its fonts to the printer. I have no idea how to implement this in awt. Could someone show me or e-mail me any sample codings on how the print functionality
can be implemented in awt and tell me what is the name of the api that i should be looking at.
My e-mail is freesoft_2000@yahoo.com
I really hope someone can help me
Yours Sincerely
Richard West
I want to know how to print the contents of the text area including all its fonts to the printer. I have no idea how to implement this in awt. Could someone show me or e-mail me any sample codings on how the print functionality
can be implemented in awt and tell me what is the name of the api that i should be looking at.
My e-mail is freesoft_2000@yahoo.com
I really hope someone can help me
Yours Sincerely
Richard West
•
•
Join Date: Mar 2004
Posts: 18
Reputation:
Solved Threads: 0
Here is a very basic example of how to print out a line of text in Java
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.geom.*; import java.awt.print.*; /** Simple printing application that will demonstrate how to print out simple text */ class MyPage implements Printable { public void paint (Graphics g) // This method will define what will { // be printed on paper Graphics2D g2d = (Graphics2D) g; g2d.setFont(new Font("Arial", Font.BOLD, 30)); g2d.drawString ("Hello World of Paper!", 200, 150); } public int print (Graphics g, PageFormat f, int i) { if (i != 0) // To prevent overflow. i indicates number of pages to print return NO_SUCH_PAGE; paint (g); // Call paint method return PAGE_EXISTS; } } class MyPrinter { public static void main (String[] args) { PrinterJob job = PrinterJob.getPrinterJob(); System.out.println ("Staring printer..."); job.setPrintable(new MyPage()); if (job.printDialog()) // Show the printing dialog { try { job.print(); // Attempt printing } catch (PrinterException e) { e.printStackTrace(); } } } }
![]() |
Similar Threads
- Printing problem (Java)
- Printing JTable Content with Grid (Java)
- Printing JPanel containing JLable, JTable, JButton, JTextPane, JTextArea (Java)
- Windows 2000 Adv Server and "Printing Subsystem" (Windows NT / 2000 / XP)
- Printing Embedded JComponents (Java)
- Printing from java (Java)
- Linux printing questions (*nix Hardware Configuration)
Other Threads in the Java Forum
- Previous Thread: Always on top Frame
- Next Thread: problem with lengthy query
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component converter database developmenthelp eclipse error exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie nonstatic notdisplaying number online page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





