Solved

PageFormat does not save settings

Posted on 2000-03-09
3
244 Views
Last Modified: 2012-08-13
Hi,

I want to save the Print Setup and later use it in my Print.  I want to save page orientation.  For this I use printSetup(), I set the orientation and OK.  When I call it again, the setting is lost.

I do not want to invoke printSetup() every time I go through printFrame().


PrinterJob printJob;
      PageFormat pageFormat;
      
      public void printSetup()
      {
        printJob = PrinterJob.getPrinterJob();
           
        pageFormat = printJob.pageDialog(printJob.defaultPage());
      }
      

      public void printFrame()
    {
          try {
                  printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable(this);
            if (printJob.printDialog()) {
                try {
                    printJob.print();  
                } catch (Exception ex) {   ex.printStackTrace();   }
            }                        
            } catch (java.lang.Exception e) { }      
      
      }
      
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
      return(NO_SUCH_PAGE);
    }
    else {
      Graphics2D g2d = (Graphics2D)g;
      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
      setDoubleBuffered(false);
      paint(g2d);
      setDoubleBuffered(true);
      return(PAGE_EXISTS);
    }
  }
0
Comment
Question by:akoifman
  • 2
3 Comments
 
LVL 2

Expert Comment

by:AlexJ030200
ID: 2602561
Hi Alex.

You could create your own default pageFormat and only open the dialog the first time you print something or only when a menu item for page format is clicked.

Then you use

  printJob.setPrintable(this, pageFormat);

instead of  

  printJob.setPrintable(this);

in your program.

If you want this choices to live across sessions, and per user basis, you could save a property file with the necessary information (probably paper size and orientation), and create a page format from that at the beginning of a new session.
0
 

Author Comment

by:akoifman
ID: 2608105
Thanks it worked.  Although it is not reflected in the dialog.  The dialog still shows Portrait, even if it is set (prints) to Lanscape.
0
 
LVL 2

Accepted Solution

by:
AlexJ030200 earned 100 total points
ID: 2615813
Unfortunately, your problem is a reported and not yet corrected bug in the windows implementation of Java.

You can read the last report on this error at
http://developer.java.sun.com/developer/bugParade/bugs/4197377.html

(You'll have to register to the java Development connection in order to read this, but affiliation is free).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java. non-English characters encoding problem. intellij idea 3 73
Java and GPO 11 68
Image decoding from Camera 3 72
windows explorer path to command prompt 5 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now