Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Possible bug in cross-platform print dialog

Reply
Thread Tools

Possible bug in cross-platform print dialog

 
 
Knute Johnson
Guest
Posts: n/a
 
      01-22-2008
I've found a problem using the cross-platform print dialog. On the
print dialog page setup tab there are four fields to enter margins. The
data from Top margin doesn't appear to get set into the
PrintRequestAttributeSet. If you try the code below you will see that
the Top margin is always 25.4mm no matter what you enter into the Top
field. If you uncomment the two lines that add a MediaPrintableArea
attribute to the PrintRequestAttributeSet you will notice that the Top
field then shows 2.0. However if you change it to some other value, the
new value will not be transferred to the PrintRequestAttributeSet and it
will not print the drawing at the changed top margin.

I'm pretty sure that this is a bug. If anybody has a 1.5 JRE installed
and wouldn't mind trying it and reporting back I would appreciate it.
I've tested it with 1.6 on Windows. On Fedora I get a
NullPointerException: null attribute on the line that calls the print
dialog. I don't know what the problem with that is. If anybody has any
ideas that problem with linux I could use some help there.

Thanks,

import java.awt.*;
import java.awt.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class PrintTest implements Printable {
private void render(Graphics g, PageFormat pf) {
g.drawRect((int)pf.getImageableX(),(int)pf.getImag eableY(),
72,72);
g.drawLine((int)pf.getImageableX(),(int)pf.getImag eableY(),

72,72);
g.drawLine((int)pf.getImageableX() + 72,(int)pf.getImageableY(),
(int)pf.getImageableX(),(int)pf.getImageableY() + 72);
}

public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
int retcod = Printable.PAGE_EXISTS;
if (pageIndex == 0) {
render(g,pageFormat);
} else
retcod = Printable.NO_SUCH_PAGE;

return retcod;
}

public static void main(String[] args) {
PrintTest pt = new PrintTest();
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(pt);
HashPrintRequestAttributeSet set =
new HashPrintRequestAttributeSet();
// set.add(new MediaPrintableArea(25.4f,50.8f,165.1f,203.2f,
// MediaPrintableArea.MM));
if (pj.printDialog(set)) {
Attribute[] atts = set.toArray();
for (Attribute att : atts)
System.out.println(att);
/*
try {
pj.print(set);
} catch (PrinterException pe) {
pe.printStackTrace();
}
*/
}
}
}

--

Knute Johnson
email s/nospam/knute/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDem
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Problem - I want to print Current Output of Pdf file and shouldprint once.I get print dialog box but it is not working Lew Java 0 05-30-2007 01:31 PM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
How can i print from the broweser without displaying the dialog print ? Tamer Ibrahim ASP .Net 3 01-29-2007 10:52 AM
display print preview dialog, not print dialog Matt Javascript 1 11-20-2004 01:18 AM
Cannot press OK in Windows Print Dialog / How can i print in Windows ? mzo Python 0 01-13-2004 04:55 PM



Advertisments