Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Printing routine flips my text by 180 degrees

Thread view: 
lemmi - 29 Mar 2007 15:18 GMT
Hi,

I have a problem with a printing routine I wrote for a Swing
component. For some reason all text elements (g.drawString()) appear
rotated (by 180 degrees) when I use LANDSCAPE orientation. Has anyone
seen this before?

Dirk
Daniel Pitts - 29 Mar 2007 23:37 GMT
> Hi,
>
[quoted text clipped - 4 lines]
>
> Dirk

If you post an sscce <http://www.physci.org/codes/sscce.html>, it
might help us make suggestions for you.
Alexander Schölling - 18 Apr 2007 08:53 GMT
Daniel Pitts schrieb:
>> Hi,
>>
[quoted text clipped - 7 lines]
> If you post an sscce <http://www.physci.org/codes/sscce.html>, it
> might help us make suggestions for you.

The following code exhibits this problem:

------
/*
 * GraphPageable.java
 *
 * Created on 27. Februar 2007, 10:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.gpkom.graph;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import org.jfree.chart.JFreeChart;

/**
 * Printer class for a graph
 * @author Alexander Schölling
 */
public class GraphPageable implements Printable {

    /**
     * Creates a new instance of GraphPageable
     * @param g Graph
     */
    public GraphPageable(JFreeChart g) {
        graph=g;
    }

    /**
     * Printing dialogs and printing
     * @throws java.awt.print.PrinterException Passed through from
PrinterJob.print()
     */
    public void print() throws PrinterException {
        PrinterJob job=PrinterJob.getPrinterJob();
        PageFormat alt=job.defaultPage();
        PageFormat format=job.pageDialog(alt);
        if (format.equals(alt)) return;
        job.setPrintable(this, format);
        if (job.printDialog()) {
            job.print();
        }
    }

    /**
     * Printing
     * @param graphics GraphicsContext
     * @param pageFormat PaqeFormat
     * @param i Page number
     * @throws java.awt.print.PrinterException Passed through
     * @return Printable.NO_SUCH_PAGE or Printable.PAGE_EXISTS
     */
    public int print(Graphics graphics, PageFormat pageFormat, int i)
throws PrinterException {
        if (i>0) return Printable.NO_SUCH_PAGE;
        Graphics2D g2=(Graphics2D)graphics;
        g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
        graph.draw(g2, new
Rectangle((int)pageFormat.getImageableWidth(),
(int)pageFormat.getImageableHeight()));
        return Printable.PAGE_EXISTS;
    }

    private JFreeChart graph;
}
-----

As soon as I change the orientation from portrait to landscape _in the
print dialog_, the strings (Graph label, title, etc.) are turned upside
down. Even the diagonally printed strings are turned 180°.

Yours,

Alexander


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.