Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 31

Thread: Another printing topic

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Another printing topic

    Hey guys,
    I know I'm new and all (And most of you will hate me for doing this).
    But I got one small problem with printing.

    As you see, i made my very own notepad. And I'm kinda stuck with getting the text from the user into the picture.



    //Global variable for the text.
    String textPrint;
     
      private void printMenuActionPerformed(java.awt.event.ActionEvent evt) {     
        textPrint = text.getText(); //text = the user input                                     
        PrinterJob pj = PrinterJob.getPrinterJob();
        PageFormat pf = pj.defaultPage();
        Paper paper = new Paper();
        double margin = 36; // half inch
        paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
            paper.getHeight() - margin * 2);
        pf.setPaper(paper);
     
        pj.setPrintable(new notepad(), pf);
        if (pj.printDialog()) {
          try {
            pj.print();
          } catch (PrinterException e) {
            System.out.println(e);
          }
        }        
     
        }                                         
     
     
     
           public int print(Graphics g, PageFormat pf, int pageIndex) {         
        if (pageIndex != 0)        
        return NO_SUCH_PAGE;        
        Graphics2D g2 = (Graphics2D) g;
        g2.setFont(new Font(FontPrint, Font.PLAIN, fontS));
        g2.setPaint(Color.black);   
        g2.drawString(textPrint, 100, 100);      
        return PAGE_EXISTS;
      }

    When I use this method, I get blank sheet that gets printed. No errors.
    The problem lies with the variable and i don't know a way around it.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Another printing topic

    After skimming through the code, my immediate suspicion is this line:
    pj.setPrintable(new notepad(), pf);

    Are you aware that you are sending a new notepad() object, which I can only assume is blank.

    EDIT: If that's not the solution, the next thing I would ask is what you are using to create your Notepad thingy. Is it a JTextArea? Because if so, why not just call the JTextArea.print() method (inherited from JTextComponent)?
    Last edited by aussiemcgr; April 2nd, 2012 at 05:40 PM.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Ajan (April 3rd, 2012)

  4. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    wow guess netbeans filled it out for me, and I never took note of it.
    only problem now is, my lining isn't correct. If its multiple lines, it just gets printed as one. I dont know how to fix this one..
    Last edited by Ajan; April 2nd, 2012 at 05:45 PM.

  5. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Another printing topic

    That's a by-product of the g2.drawString(...) method. By default, that method only supports single-line text. Trying to break this up in multiple lines is a hell of a task. You might find these two solutions helpful:
    java - How to output a String on multiple lines using Graphics - Stack Overflow
    java - Problems with newline in Graphics2D.drawString - Stack Overflow
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  6. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Ajan (April 3rd, 2012)

  7. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    the second link is a bit helpful to see a way, but then i will need /n through out the text. which i dont know how to replace blank spaces and then replace it.
    im trying to get a way around it now, but i cant seem to find one.
    Only guess is, to think outside the box.

    Have something like this:
    Make a new file with the data on it
    open file
    make a scanner
    make a while loop that will read the text on it
    then String data = data + "/n" + x.nextLine();
    then use
    private void drawString(Graphics g, String text, int x, int y) {
    for (String line : text.split("\n"))
    g.drawString(line, x, y += g.getFontMetrics().getHeight());
    }
    once all this is done, delete the file.

    something like that??????
    Last edited by Ajan; April 2nd, 2012 at 06:31 PM.

  8. #6
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    ^ would this work?

  9. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    would this work?
    What happens when you compile and execute the code? Does it do what you want?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #8
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    i tried it yesterday, doesnt work :/ just prints the line together.

  11. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    just prints the line together.
    Please explain what you are seeing.
    Can you post a small, simple program that compiles, executes and shows what you are talking about?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #10
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    Here is the code:

    it follows this:
    Make a new file with the data on it
    open file
    make a scanner
    make a while loop that will read the text on it
    then String data = data + "/n" + x.nextLine();
    then use
    private void drawString(Graphics g, String text, int x, int y) {
    for (String line : text.split("\n"))
    g.drawString(line, x, y += g.getFontMetrics().getHeight());
    }
    once all this is done, delete the file.


    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.font.LineBreakMeasurer;
    import java.awt.font.TextLayout;
    import java.awt.geom.Point2D;
    import java.awt.print.Book;
    import java.awt.print.PageFormat;
    import java.awt.print.Paper;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.Writer;
    import java.text.AttributedCharacterIterator;
    import java.text.AttributedString;
    import java.util.Formatter;
    import java.util.Scanner;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    import javax.swing.filechooser.FileFilter;
     
    import java.awt.print.Printable;
     
    /**
     *
     * @author Adam
     */
    public class Frame extends javax.swing.JFrame implements Printable {
     
     
        String FontPrint, textPrint;
        AttributedString mStyledText;
     
     
        public Frame() {
            initComponents();
        }
     
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jScrollPane1 = new javax.swing.JScrollPane();
            text = new javax.swing.JTextArea();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            text.setColumns(20);
            text.setRows(5);
            jScrollPane1.setViewportView(text);
     
            jMenu1.setText("File");
     
            jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
            jMenuItem1.setText("Print");
            jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem1ActionPerformed(evt);
                }
            });
            jMenu1.add(jMenuItem1);
     
            jMenuBar1.add(jMenu1);
     
            jMenu2.setText("Edit");
            jMenuBar1.add(jMenu2);
     
            setJMenuBar(jMenuBar1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>
     
        private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
     
               String textPrintdata = text.getText();
            Writer outputPrint = null;
            File x = new File("C:\\temporarytextdocumentusedtoprintforajansnotepad.txt");
            if (x.exists()) {
                x.delete();
                try {
                    outputPrint = new BufferedWriter(new FileWriter(x));
                    outputPrint.write(textPrintdata);
                    outputPrint.close();
                } catch (Exception E) {
                }
            } else {
                final Formatter xtxt;
                try {
                    xtxt = new Formatter(x);
                    xtxt.format(textPrintdata);
                    xtxt.close();
                } catch (Exception E) {
                }
     
            }
     
            File f = new File("C:\\temporarytextdocumentusedtoprintforajansnotepad.txt");
            Scanner xOpen;
            String data = "";
            text.setText("");
            try {
                xOpen = new Scanner(f);
                while (xOpen.hasNext()) {
                    textPrint = textPrint + "\n" + xOpen.nextLine();
                }
                xOpen.close();
                f.delete();
            } catch (Exception E) {
            }
            mStyledText = new AttributedString(textPrint);
     
            PrinterJob printerJob = PrinterJob.getPrinterJob();
            Book book = new Book();
            book.append(this, new PageFormat());
            printerJob.setPageable(book);
            boolean doPrint = printerJob.printDialog();
            if (doPrint) {
                try {
                    printerJob.print();
                } catch (PrinterException exception) {
                    System.err.println("Printing error: " + exception);
                }
            }
     
     
     
     
        }
     
     
     
     
        private void drawString(Graphics g, String text, float x, float y) {
            for (String line : text.split("\n"))
               g.drawString(line, (int) x, (int) y);
        }
     
        public int print(Graphics g, PageFormat format, int pageIndex) {
     
            Graphics2D g2d = (Graphics2D) g;
     
            g2d.translate(format.getImageableX(), format.getImageableY());
     
            g2d.setFont(new Font("monospaced", Font.PLAIN, 42));
            g2d.setPaint(Color.black);
     
            Point2D.Float pen = new Point2D.Float();
            AttributedCharacterIterator charIterator = mStyledText.getIterator();
            LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());
            float wrappingWidth = (float) format.getImageableWidth();
            while (measurer.getPosition() < charIterator.getEndIndex()) {
                TextLayout layout = measurer.nextLayout(wrappingWidth);
                pen.y += layout.getAscent();
                float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout.getAdvance());
                drawString(g2d,textPrint, pen.x + dx, pen.y );
                pen.y += layout.getDescent() + layout.getLeading();
            }
            return Printable.PAGE_EXISTS;
        }
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url] 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
                    new Frame().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea text;
        // End of variables declaration
    }

  13. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    Can you make a program that only needs to be compiled and executed to show the problem. The code you posted looks like it wants to read some file. Remove any need for anything besides the code to show the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #12
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    norm, the code i showed earlier makes a file with the text from the text area and then reads the file with it. i did this to use the x.next() method for the while loop and make so i can have this algorithim in it: data = data + x.nextline(). i hope you understand what i mean.

  15. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    I'd rather not do all that.
    Can you hardcode a string and use that vs all the other stuff.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #14
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    yea but the thing is, if i hard code a string it wont work the way i want it to. as you can see, i want the user to print all text on the text area.
    im trying to make the program atm print out the lines, instead of it just giving it as one line.
    norm do you have any other methods i could try?

  17. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    What is the problem that you are trying to solve? I thought it was using the drawString() method to draw a multi-line String. The rest of the code is in the way for testing that problem. In fact you do not need to print to test. You can work on the technique in a paintComponent() method.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #16
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    I think i need to do another approach to the printing method, does anyone else have another way in which i could try?

  19. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    Can you state what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  20. #18
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    norm, my problem is i cant figure out a printing method where it will print multiple lines and keep within the margins at the same time.
    so atm i dont know how :S

  21. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    You need to set the x and y values for each line you draw with drawString().
    For testing you could override the paintComponent in a JPanel and do the drawing there.

    From db on another forum:
    And to find how much space the String will occupy, use the methods of FontMetrics or TextLayout
    Last edited by Norm; April 4th, 2012 at 07:08 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #20
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    Soz norm for the long wait for my reply. I was away for easter and came back to see my pc was broken. All fixed now.


    Ok so can you help me through this?

    ill start of, can you guide me through this please?

    public class JavaPrint implements Printable{
     
    }

  23. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    Can you explain and ask a specific programming question?
    If you don't understand my answer, don't ignore it, ask a question.

  24. The Following User Says Thank You to Norm For This Useful Post:

    Ajan (April 12th, 2012)

  25. #22
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    Ok, im trying to make a notepad, and i am trying to get the print method to work as i want it to.

    1) Must print multiple lines
    2) Must print within a certain area
    3) Must print more than one line.

    But I keep getting errors where 1) doesn't even work.

  26. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    But I keep getting errors
    Please post the full text of the error messages.

    When using the methods of the Graphics, you are responsible for positioning where everything goes that is "printed" using a draw method. The drawString() method does not look at the contents of a String to decide where to position any part of the String.
    If you don't understand my answer, don't ignore it, ask a question.

  27. The Following User Says Thank You to Norm For This Useful Post:

    Ajan (April 12th, 2012)

  28. #24
    Junior Member
    Join Date
    Apr 2012
    Posts
    21
    My Mood
    Torn
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Another printing topic

    ok so i dont get syntax errors, just visual errors.

    Say like i type into the text area:

    Hello my name is slim shady.
    Hello

    it will repeat itself multiple times(on top of each other.)


    Here is the method:

     private void printMenuActionPerformed(java.awt.event.ActionEvent evt) {                                          
            String textPrintdata = text.getText();
            Writer outputPrint = null;
            File x = new File("C:\\temporarytextdocumentusedtoprintforajansnotepad.txt");
            if (x.exists()) {
                x.delete();
                try {
                    outputPrint = new BufferedWriter(new FileWriter(x));
                    outputPrint.write(textPrintdata);
                    outputPrint.close();
                } catch (Exception E) {
                }
            } else {
                final Formatter xtxt;
                try {
                    xtxt = new Formatter(x);
                    xtxt.format(textPrintdata);
                    xtxt.close();
                } catch (Exception E) {
                }
     
            }
     
            File f = new File("C:\\temporarytextdocumentusedtoprintforajansnotepad.txt");
            Scanner xOpen;
            String data = "";
            text.setText("");
            try {
                xOpen = new Scanner(f);
                while (xOpen.hasNext()) {
                    textPrint = textPrint + "\n" + xOpen.nextLine();
                }
                xOpen.close();
                f.delete();
            } catch (Exception E) {
            }
            mStyledText = new AttributedString(textPrint);
     
     
     
     
            PrinterJob printerJob = PrinterJob.getPrinterJob();
            Book book = new Book();
            book.append(this, new PageFormat());
            printerJob.setPageable(book);
            boolean doPrint = printerJob.printDialog();
            if (doPrint) {
                try {
                    printerJob.print();
                } catch (PrinterException exception) {
                    System.err.println("Printing error: " + exception);
                }
            }
        }                                         
     
     
     
     
        private void drawString(Graphics g, String text, float x, float y) {
            for (String line : text.split("\n"))
               g.drawString(line, (int) x, (int) y);
        }
     
        public int print(Graphics g, PageFormat format, int pageIndex) {
            /* We'll assume that Jav2D is available.
             */
            Graphics2D g2d = (Graphics2D) g;
            /* Move the origin from the corner of the Paper to the corner
             * of the imageable area.
             */
            g2d.translate(format.getImageableX(), format.getImageableY());
            /* Set the text color.
             */
            g2d.setFont(new Font(FontPrint, Font.PLAIN, fontS));
            g2d.setPaint(Color.black);
            /* Use a LineBreakMeasurer instance to break our text into
             * lines that fit the imageable area of the page.
             */
            Point2D.Float pen = new Point2D.Float();
            AttributedCharacterIterator charIterator = mStyledText.getIterator();
            LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());
            float wrappingWidth = (float) format.getImageableWidth();
            while (measurer.getPosition() < charIterator.getEndIndex()) {
                TextLayout layout = measurer.nextLayout(wrappingWidth);
                pen.y += layout.getAscent();
                float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout.getAdvance());
                drawString(g2d,textPrint, pen.x + dx, pen.y );
                pen.y += layout.getDescent() + layout.getLeading();
            }
            return Printable.PAGE_EXISTS;
        }

  29. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Another printing topic

    on top of each other
    That is what will happen when you draw multiple Strings at the same location.
    Change the values of x and/or y so each String is drawn at its own location.
    If you don't understand my answer, don't ignore it, ask a question.

  30. The Following User Says Thank You to Norm For This Useful Post:

    Ajan (April 12th, 2012)

Page 1 of 2 12 LastLast

Similar Threads

  1. Best way to teach/learn code/java. (topic for fun)
    By JonLane in forum Java Theory & Questions
    Replies: 2
    Last Post: February 23rd, 2012, 08:54 PM
  2. Need Beginners resource for Filter And Listener Topic
    By ashishrajiit in forum Java Servlet
    Replies: 1
    Last Post: October 20th, 2011, 06:18 AM
  3. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  4. Off Topic: Happy Songs?
    By KevinWorkman in forum The Cafe
    Replies: 5
    Last Post: March 3rd, 2011, 09:46 PM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM