Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4221166

pageDialog() does not support landscape format

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • 2d
    • generic
    • generic



      Name: vi73552 Date: 03/17/99


      ------ Win32 -----

      Using pageDialog() from the java.awt.print package,
      when you specify a landscape PageFormat, this format
      is taken into account in the pageDialog() window (landcape format selected !),
      but not when printed !!! A portrait format is printed...

      Source code as follow :

                       import javax.swing.*;
                       
                       import java.awt.print.*;
                       import java.awt.*;
                       import java.awt.event.*;

                       public class TestPageDialog extends JFrame implements Printable {

                         JPanel pane;

                         /////////////////////////////////////////////////////////
                         public TestPageDialog() {
                           this.setTitle("Testing Page dialog in Landscape Mode");
                           this.addWindowListener(new WindowAdapter() {
                             public void windowClosing(WindowEvent e) {System.exit(0);}});


                           pane = new JPanel();
                           JTextField jtf = new JTextField("Hello, boy, this text needs to be long for this example to work (not fitting in a page) (landscape)");
                           pane.add(jtf);
                           pane.setPreferredSize(new Dimension(600, 80));
                           this.getContentPane().setLayout(new BorderLayout());
                           this.getContentPane().add(BorderLayout.CENTER, pane);
                           this.pack();
                           JButton printButton= new JButton();

                           printButton.setText("Print me!");

                           this.getContentPane().add(BorderLayout.SOUTH, printButton);

                           // for faster printing turn double buffering off
                           RepaintManager.currentManager(
                               this).setDoubleBufferingEnabled(false);

                           printButton.addActionListener( new ActionListener(){
                              public void actionPerformed(ActionEvent evt) {
                                PrinterJob pj=PrinterJob.getPrinterJob();

                                pj.setPrintable(TestPageDialog.this);
                                //Use these following lines to swap orientation
                                //PageFormat portrait = pj.defaultPage();
                                //portrait.setOrientation(PageFormat.PORTRAIT);
                                PageFormat landscape = pj.defaultPage();
                                landscape.setOrientation(PageFormat.LANDSCAPE);

                                pj.pageDialog(landscape);

                                try {
                                    pj.print();
                                }catch (Exception PrintException) {}
                              }
                           });

                           this.setVisible(true);
                         }

                         /////////////////////////////////////////////////////////
                         public int print(Graphics g, PageFormat pageFormat,
                               int pageIndex) throws PrinterException {

                           if (pageIndex >= 1) {
                              return Printable.NO_SUCH_PAGE;
                           }
                              Graphics2D g2 = (Graphics2D)g;
                              g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                              Font f = new Font("Monospaced",Font.PLAIN,12);
                              g2.setFont (f);
                              paint (g2);
                              return Printable.PAGE_EXISTS;
                          }


                         /////////////////////////////////////////////////////////
                         public static void main(String[] args) {
                           new TestPageDialog();
                         }
                       }
      (Review ID: 55619)
      ======================================================================

            Unassigned Unassigned
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: