?
Solved

PageFormat does not save settings

Posted on 2000-03-09
3
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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