PageFormat does not save settings

Posted on 2000-03-09
Medium Priority
Last Modified: 2012-08-13

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();
            if (printJob.printDialog()) {
                try {
                } catch (Exception ex) {   ex.printStackTrace();   }
            } catch (java.lang.Exception e) { }      
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    else {
      Graphics2D g2d = (Graphics2D)g;
      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
Question by:akoifman
  • 2

Expert Comment

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  


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.

Author Comment

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.

Accepted Solution

AlexJ030200 earned 400 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

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

607 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