Solved

PageFormat does not save settings

Posted on 2000-03-09
3
248 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

742 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