The Artima Developer Community
Sponsored Link

Java Answers Forum
Java PrintComponents Setting Default Fonts...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Java PrintComponents Setting Default Fonts... Posted: Feb 10, 2005 2:10 AM
Reply to this message Reply
Advertisement
Hi Folks:

I have a Print function in a Swing application and the
Default Font being used by the printer is extremely
large such that when it prints my Swing Component,
the text (only the text and not the Swing Components)
gets cut off...

It doesn't even adhere to the font that my Swing
Components are using.

I have tried to do the following:


public void print(){
PrinterJob printJob = PrinterJob.getPrinterJob();

PageFormat pf = printJob.defaultPage();
pf.setOrientation(PageFormat.PORTRAIT);

//pf.setFont(pageFont);

Paper paper = new Paper();
paper.setSize(6100, 5520);
paper.setImageableArea(45, 45, 7000, 6300);

pf.setPaper(paper);
printJob.setPrintable(this, pf);

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{
// Font setting
Font pageFont = new Font("Arial", Font.PLAIN, 8);
g.setFont(pageFont);
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}
}


But to no avail. Any suggestions would be appreciated.

Thanks in advance.

Spike

Topic: jTDS JDBC Driver 1.0.1 released Previous Topic   Next Topic Topic: java mechanics

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use