Possible bug in cross-platform print dialog

Discussion in 'Java' started by Knute Johnson, Jan 22, 2008.

  1. 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.


    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.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) {
    } else
    retcod = Printable.NO_SUCH_PAGE;

    return retcod;

    public static void main(String[] args) {
    PrintTest pt = new PrintTest();
    PrinterJob pj = PrinterJob.getPrinterJob();
    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)
    try {
    } catch (PrinterException pe) {


    Knute Johnson
    email s/nospam/knute/

    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    Knute Johnson, Jan 22, 2008
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page