Solved

PageFormat does not save settings

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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.

747 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

10 Experts available now in Live!

Get 1:1 Help Now