Results 1 to 2 of 2
  1. #1
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default Trying to print from a JTextArea

    I am tring to print from a JTextArea. I don't really need to display the JTextArea, just using it to get at the print() function that exists.

    I have set the content type to text/html send it some HTML text. When I do print it, the text comes out very large (what shoudl be a 7 page document comes out as 14 pages)

    I have tried to change the font, with the setFont I have tried putting something in the HTML to change the font, it seams as the print function ignores the font and uses the default (over large) font.

    Is there a call I am missing to apply the font size. etc..

    Basicly assume code that follows the kind of logic below as
    Java Code:
    public void printText(String htmlCodedText)
    {
       JTextArea textToPrint = new JTextArea();
       textToPrint.setContextType("text/html");
       textToPrint.setText(htmlCodedText);
       // here I have tried 
       // textToPrint.setFont(text.getFontName(),Font.NORMAL,text.getFontSize()/2);
       try
       {
           textToPrint.print();
        }
       catch(/*the exceptions)
       {
          //handle it
        }
    }
    Also when doing headers and footers and I try to add newlines. It does not put the new lines in headers or footers, I have tested with system.out.printlns and the new lines were there but when sending them to the print fuction it seams it strips the new lines out of it, and prints them all on 1 line.
    Last edited by Drun; 09-01-2010 at 07:09 PM.
    Michael P. O'Connor
    http://www.mikeoconnor.net

  2. #2
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Question

    Quote Originally Posted by Drun View Post
    I am tring to print from a JTextArea. I don't really need to display the JTextArea, just using it to get at the print() function that exists.

    I have set the content type to text/html send it some HTML text. When I do print it, the text comes out very large (what shoudl be a 7 page document comes out as 14 pages)

    I have tried to change the font, with the setFont I have tried putting something in the HTML to change the font, it seams as the print function ignores the font and uses the default (over large) font.

    Is there a call I am missing to apply the font size. etc..

    Basicly assume code that follows the kind of logic below as
    Java Code:
    public void printText(String htmlCodedText)
    {
       JTextArea textToPrint = new JTextArea();
       textToPrint.setContextType("text/html");
       textToPrint.setText(htmlCodedText);
       // here I have tried 
       // textToPrint.setFont(text.getFontName(),Font.NORMAL,text.getFontSize()/2);
       try
       {
           textToPrint.print();
        }
       catch(/*the exceptions)
       {
          //handle it
        }
    }
    Also when doing headers and footers and I try to add newlines. It does not put the new lines in headers or footers, I have tested with system.out.printlns and the new lines were there but when sending them to the print fuction it seams it strips the new lines out of it, and prints them all on 1 line.

    What are the codes of the print() function, that u r using???

Similar Threads

  1. help me with JTextArea
    By javanew in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 08:51 PM
  2. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  3. system-print(ln) on jtextarea or jpanel
    By Tamu in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2008, 05:18 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. JTextArea
    By saytri in forum New To Java
    Replies: 0
    Last Post: 01-13-2008, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •