Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » Java

 Page 1 of 1 [ 1 post ] 

Author Message
 Post subject: Diff font size n printin
 Post Posted: Mon Oct 26, 2009 7:33 pm 

Joined: Sat Feb 21, 2009 1:03 pm
Posts: 47

I m havin a issue on printin J Panel. The printin class was da following:

package MyPackage;
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

public class PrintUtilities implements Printable {
  private Component componentToBePrinted;

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

  public PrintUtilities(Component componentToBePrinted) {
    this.componentToBePrinted = componentToBePrinted;

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

  public int print(Graphics g, PageFormat pf, int pageIndex) {
    int response = NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = componentToBePrinted.getSize();
    double panelWidth = d.width;
    double panelHeight = d.height;
    double pageHeight = pf.getImageableHeight();
    double pageWidth = pf.getImageableWidth();
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
    if (pageIndex >= totalNumPages) {
       response = NO_SUCH_PAGE;
    else {
       g2.translate(pf.getImageableX(), pf.getImageableY());
       g2.translate(0f, -pageIndex * pageHeight);
        g2.scale(scale, scale);
        response = Printable.PAGE_EXISTS;
    return response;

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

  public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);

The prob was dat font size on JPanel, when it was printd, is huge!! So I was forced
2 set Font size 2 10 in order 2 havin a decent printin ; however dis setting make legibility (on screen) very difficult. What could I do?

Display posts from previous:  Sort by  
 Page 1 of 1 [ 1 post ] 

Board index » Server Side Development » Java

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: