Possible bug in cross-platform print dialog

K

Knute Johnson

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.getImageableY(),
72,72);
g.drawLine((int)pf.getImageableX(),(int)pf.getImageableY(),

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();
}
*/
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top