Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing in Landscape mode

0 views
Skip to first unread message

Rob Ross

unread,
Mar 21, 2002, 9:01:18 PM3/21/02
to
Is there something special I have to know/do to get my paper to print in
Landscape mode?

I'm putting up a printer dialog with

PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(this);
if (pj.printDialog())
{
try{
pj.print();
}
catch (Exception e)
{
e.printStackTrace();
}
}

In the dialog, I'm clicking on the Properties...button, then selecting the
Landscape radio button.

In my print() method, I'm using PageFormat.getImageableHeight() and
PageFormat.getImageableWidth() to base my drawing calculations on.

But the width and height never seem to change whether I have selected
Portrait or Landscape.

So how do I tell the PrintFormat to switch to landscape mode? And why does
my choice in the Print dialog get ignored?

Thanks.

--
Rob Ross

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
To reply, simply remove what Mr. Charlton Heston might say.

Linda Radecke

unread,
Mar 22, 2002, 2:59:56 AM3/22/02
to

Rob Ross wrote:

> Is there something special I have to know/do to get my paper to print in
> Landscape mode?

> I'm putting up a printer dialog with

> PrinterJob pj=PrinterJob.getPrinterJob();

>pj.setPrintable(this);
^^^^

pjob.setPrintable(this, pageFormat);


>if (pj.printDialog())

> {
> try{
> pj.print();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }

> In the dialog, I'm clicking on the Properties...button, then selecting the
> Landscape radio button.

> In my print() method, I'm using PageFormat.getImageableHeight() and
> PageFormat.getImageableWidth() to base my drawing calculations on.

> But the width and height never seem to change whether I have selected
> Portrait or Landscape.

> So how do I tell the PrintFormat to switch to landscape mode? And why does
> my choice in the Print dialog get ignored?

This is related to your line:

>pj.setPrintable(this);

instead:

pjob.setPrintable(this, pageFormat);

Selecting the orientation can be done via the properties, however it
is usually done via the PageDialog, to get this you set in addition:

PageFormat pageFormat = pj.pageDialog(pj.defaultPage());

pjob.setPrintable(this, pageFormat);


To determine LANDSCAPE programatically you can set:

pageFormat.setOrientation(PageFormat.LANDSCAPE);

Linda
--
(=)
/ li...@jalice.ch - http://www.jalice.net
(=)
/ l.ra...@hswzfh.ch - http://www.hswzfh.ch
(=)


Linda Radecke

unread,
Mar 22, 2002, 3:02:20 AM3/22/02
to

Rob Ross wrote:


> Is there something special I have to know/do to get my paper to print in
> Landscape mode?

> I'm putting up a printer dialog with

> PrinterJob pj=PrinterJob.getPrinterJob();

>pj.setPrintable(this);
^^^^

pj.setPrintable(this, pageFormat);


>if (pj.printDialog())

> {
> try{
> pj.print();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }

> In the dialog, I'm clicking on the Properties...button, then selecting the
> Landscape radio button.

> In my print() method, I'm using PageFormat.getImageableHeight() and
> PageFormat.getImageableWidth() to base my drawing calculations on.

> But the width and height never seem to change whether I have selected
> Portrait or Landscape.

> So how do I tell the PrintFormat to switch to landscape mode? And why does
> my choice in the Print dialog get ignored?

This is related to your line:

>pj.setPrintable(this);

instead:

pj.setPrintable(this, pageFormat);

Selecting the orientation can be done via the properties, however it
is usually done via the PageDialog, to get this you set in addition:

PageFormat pageFormat = pj.pageDialog(pj.defaultPage());

pj.setPrintable(this, pageFormat);

Simon Lewington

unread,
Mar 22, 2002, 4:46:29 AM3/22/02
to comp.lang.java.gui
"Rob Ross" <robNOA...@earthlink.net> wrote:

> Is there something special I have to know/do to get my paper to print in
> Landscape mode?
>
> I'm putting up a printer dialog with

<snip>
> if (pj.printDialog())
<snip>


> In the dialog, I'm clicking on the Properties...button, then selecting the
> Landscape radio button.

I'm afraid this doesn't affect the pageFormat - something which caused no
end of hassle for users of my app - you'll need to use
PrinterJob.pageDialog(PageFormat) to change the orientation. Fortunately,
this is all sorted in J 1.4 (even without changing your code) since the
printDialog() dialog now has a setup button on it.

Simon.


Rob Ross

unread,
Mar 23, 2002, 7:58:52 AM3/23/02
to
Thank you all!

Yes, I spent a day wrestling with that and ended up having to display both
the Page Setup dialog AND the print dialog when the user selects my
"Print..." menu item.

It's not very elegant! I'm glad this is fixed in 1.4....yet another reason
to migrate.

Thanks.

--
Rob Ross

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
To reply, simply remove what Mr. Charlton Heston might say.

"Simon Lewington" <simonle...@metacrawler.com> wrote in message
news:TCSF609...@tcosoftware.com...

0 new messages