Printing the text in JTextPane

Hello
I need to print the text in a text pane. It prints the first page of the text pane and it doesn't print the rest of the text. I don't know what the problem is.
The code I am using, is below. I
Thank you.
LilyLay
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintUtilities implements Printable {
private Component componentToBePrinted;
public static void printComponent(Component c) {
new PrintUtilities(c).print();
public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);

Could it be that in your print(Graphics g, ...) method you are saying if pageIndex is greater than 0 return. If you are using 0 based page numbers, that would print page 0 (the first page) and none after that.

Similar Messages

  • Problems with printing the text in JTextPane

    Hello
    I need to print the text in a text pane. It prints the first page of the text pane and it doesn't print the rest of the text. I don't know what the problem is.
    The code I am using, is below. I
    Thank you.
    LilyLay
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    public class PrintUtilities implements Printable {
    private Component componentToBePrinted;
    public static void printComponent(Component c) {
    new PrintUtilities(c).print();
    public PrintUtilities(Component componentToBePrinted) {
    this.componentToBePrinted = componentToBePrinted;
    public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    if (printJob.printDialog())
    try {
    printJob.print();
    } catch(PrinterException pe) {
    System.out.println("Error printing: " + pe);
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    return(NO_SUCH_PAGE);
    } else {
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    disableDoubleBuffering(componentToBePrinted);
    componentToBePrinted.paint(g2d);
    enableDoubleBuffering(componentToBePrinted);
    return(PAGE_EXISTS);
    public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
    public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);

    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    return(NO_SUCH_PAGE);
    } else {if (pageIndex > 0) return (NO_SUCH_PAGE)
    prevents printing any more than the first page.
    change >0 to >= numPages
    Howard Amos

  • How to print the text in points wise in sap script

    hi friends,
    how to print the text in points wise in sap script.
    ex: if suppose paragraph consists of 15 lines. then according to one sentence or one fullstop (.) it should give point 1. like that...
    1. hai how ru.
    2. what r  u doing.
    3.where r u.
    like this i want numbering.. waiting for ur replys.
    thanks,
    kiran

    declare a counter
    data : cnt type char 4.
    print :
    cnt = cnt + 1.
    &cnt& &text&
    cnt = cnt + 1. and so on.
    or.
    if the data is in an internal table
    loop at internal_table.
    cnt = cnt + 1.
    write form.
    in script -&cnt& &text&
    endloop.
    Edited by: NIKHILKUMAR POOJARI on Nov 17, 2008 11:18 AM

  • How to print the text in only last but one page in sapscripts

    hiiiiiiiiiii,
             explian how to print the text in only last but one page in sapscripts? wher to write the code? plz if possible explain in detail with an example?

    Hello,
    The total no pages is given by &SAPSCRIPT-FORMPAGES& command.
    So u can handle the situation in ur form like this
    /: if &PAGE&  = &SAPSCRIPT-FORMPAGES&
    p1 TEXT
    /: endif
    Try in this way it may help u.
    Regards

  • In Pages (5.2), in a table, superscript is not only not printing, but not printing the text around it. Bizarre

    In Pages (5.2), in a table, superscript is not only not printing, but not printing the text around it. Any answers?

    Known issue now for almost 9 months.
    Use Pages '09 if you have it.
    Peter

  • How to print the texts retrived by using READ_TEXT fun module in Smartform

    Please tell me how to print the text which is rertrived by using the READ_TEXT function module in smartform.
    I have coded all things in the program lines and in that i am retriveing the long texts.
    I am getting the text lines in my internal table clearly, the thing is that I am not able to pass these lines to the text.
    I have to print the trouble ticket. in that the notes log I have to pass.
    its urgent. Points will be rewarded for any type of clue. whether it will work or not.

    There are a few ways to do it. If you need to take all of the text in the text type, in your SF text element choose "Include Text".
    Populate the fields with the data that corresponds to the text type. It is similar to the interface to the FM "Read_Text.
    Text Name
    Text Obje
    Text ID 
    Language
    Encase any variables with the "&" symbol.
    If you have already coded the call to the FM "READ_TEXT" and loaded the text into an internal table, create a loop and loop through the itab. Inside of the loop create a text element and add a variable in the text element for the field you are looking to output.

  • I need to print the text in secondary window in script

    hi all,
    how to print the text of purchase order (me22n) in script.
    plzz  explain with steps
    thanks in adv
    vidya

    Good that you know how to use read_text...
    In SAP script used it as shown below, in your script window call subroutine as shown below
    Go through this example
    Ex.
    /: PERFORM <Subroutine name> IN PROGRAM <subroutine prog name>
    /:USING &<field name>&
    /:CHANGING &<field name1&
    /:ENDPERFORM
    Display &<FIELD NAME1>&
    Then create subroutine pool program and you have to write the code.
    FORM ><subroutine name> tables int_cond structure itcsy
    outt_cond structure itcsy.
    data : value(20), value1(20). "do your own declarations
    Read int_cond table index 1.
    value = int_cond-value.
    ***Use FM Read text and store the text in value1 and pass it back to SAPscript as shown below
    Read outt_cond table index 1.
    outt_cond-value = value1.
    Modify outt_cond index 1.
    ENDFORM.
    Just rough idea given above.
    Close the thread if your question is answered and reward points to all useful answers.
    Regards,
    SaiRam

  • Vertical printing the Text in Smartforms

    Hi Friends,
    Thanks in Advance,
    Is there any posibility to print the text in Vertical, in Dot Matrix Printer
    Please resolve the Issue.
    Thanks & Regards:
    Manjula.M

    Hi,
    This thread will helpful to you.
    vertical writing in smartforms
    Thanks,
    Sree.

  • I wonder about the colors in the program. When i work and later gonna print the text i have some problem. The color is not the same when im print it. One color on the screen and another when i print it why?

    I wonder about the colors in the program. When i work and later gonna print the text i have some problem. The color is not the same when im print it. One color on the screen and another when i print it why?

    I wonder about the colors in the program. When i work and later gonna print the text i have some problem. The color is not the same when im print it. One color on the screen and another when i print it why?

  • View the Text in JTextPane when we r inserting another text

    Hi,
    I have created GUI in swing where i have taken JTextPane.I am seaching some keyword which r given by the client if i found so i am creating the pdf file for that data and in JTextPane i am showing the pdf file name .....if i am getting that keyword in the database then i am showing some different color string that " keyword not found with that keyword" .........while this process takes too much time to create pdf....till that time JTextPane is not showing any text.........in this case i want that the text should show in the JTextPane once the single Pdf file get created and so on to create 100 PDF file...plase sugget me somthing ......thanx

    Hi,
    Thanks a lot for ur support..Now i am getting updated JTextPane..
    Can u provide me a link with the help of which i can use multiple threads
    1.to get information from the database.......to collect data from database.
    2.to search the keyword in that database.
    3.to print the search condition in the JTextPane
    4.Final is to create PDF.
    So i have to do above 4 steps out of which last step(4th) that is to create PDF is time consuming...So give me guidence with the help of which i can make maximum use of threads for faster execution.....thanx

  • Printing RTF-Text using JTextPane

    G'day
    Does someone know how to print the drawed content of a JTextPane/JEditorPane?
    I derived a class from JTextPane and implemented Printable:
    public void print(Graphics g)
      paintComponent(g);
    public void paintComponent(Graphics g)
      super.paintComponent(g);
    }Seems a little ugly, uhm?! It does not work :(
    I get the following errors:
    java.lang.NullPointerException
         at java.util.Hashtable.get(Hashtable.java:336)
         at java.awt.Component.getFontMetrics(Component.java:2503)
         at javax.swing.JComponent.getFontMetrics(JComponent.java:1589)
         at com.sun.java.swing.SwingUtilities2.getFRC(SwingUtilities2.java:368)
         at com.sun.java.swing.SwingUtilities2.drawChars(SwingUtilities2.java:576)
         at javax.swing.text.Utilities.drawTabbedText(Utilities.java:159)
         at javax.swing.text.GlyphPainter1.paint(GlyphPainter1.java:102)
         at javax.swing.text.GlyphView.paintTextUsingColor(GlyphView.java:472)
         at javax.swing.text.GlyphView.paint(GlyphView.java:463)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.text.ParagraphView.paint(ParagraphView.java:584)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1338)
         at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:643)
         at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:781)
         at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:760)
         at javax.swing.JComponent.paintComponent(JComponent.java:743)
         at fd.gui.Component.paintComponent(Component.java:149)Does that make any sense?
    Btw: I used Sun JRE 1.5 (Ubuntu)
    Cahadras
    Edited by: Cahadras on Oct 23, 2007 1:50 PM

    Cahadras wrote:
    ....It must be an internal bug of the Sun VM that causes this NullPointerException when the JTextPane class passes Font instances to JComponent.getFontMetrics().You may be right, but I'm going to say "careful there partner" to your statement claiming that the Sun VM must have a bug. Please see this excellent web site titled "How to Ask Questions the Smart Way" and is found here:
    http://www.catb.org/~esr/faqs/smart-questions.html
    Here's a subsection of that page titled:
    Don't Claim that you've found a bug:
    When you are having problems with a piece of software, don't claim you have found a bug unless you are very, very sure of your ground. Hint: unless you can provide a source-code patch that fixes the problem, or a regression test against a previous version that demonstrates incorrect behavior, you are probably not sure enough. This applies to webpages and documentation, too; if you have found a documentation �bug�, you should supply replacement text and which pages it should go on.
    Remember, there are many other users that are not experiencing your problem. Otherwise you would have learned about it while reading the documentation and searching the Web (you did do that before complaining, didn't you?). This means that very probably it is you who are doing something wrong, not the software.
    The people who wrote the software work very hard to make it work as well as possible. If you claim you have found a bug, you'll be impugning their competence, which may offend some of them even if you are correct. It's especially undiplomatic to yell �bug� in the Subject line.
    When asking your question, it is best to write as though you assume you are doing something wrong, even if you are privately pretty sure you have found an actual bug. If there really is a bug, you will hear about it in the answer. Play it so the maintainers will want to apologize to you if the bug is real, rather than so that you will owe them an apology if you have messed up.

  • How to Print the text in a Text Area Component

    It is really amazing how much information is out there for
    Flex but you can never find what you are looking for :-(
    I am trying to print the contents of a text area component.
    If I just do addPage(Component Name) it works but it prints the
    whole conponent including the scrollbars, on the page. I just want
    the text. If I try to put the component name.text in addPage(), I
    get a "1067: Implicit coercion of a value of type String to an
    unrelated type flash.display:Sprite." error. Does anyone know how
    to do this?
    Any help would be greatly appreciated.
    Dave

    Is there anyone who can help with this? I really need a way
    to print the results.
    Thanks.
    Dave

  • SCRIPT - How to print the text at the center of the footer window.

    In my SAP script,
    I have some text in my footer window ( which was set using tabs ).
    I need to print the footer text as centered.

    Hi sam,
    In paragraph format press standard button (default it will be coming when u go to paragraph format )
    <b>space before</b> - 0.50cm   give according to u r requirement
    space after
    <b>left margin</b>   - 0.5 cm  give according to u r requirement
    right margin
    ( or )
    directly u can give
    <b>alignment - CENTER</b>

  • I printed an AutoCad drawing to PDF and the PDF looks OK on the screen but when I print the PDF to a printer the text in the drawing is crosshatched with lines and you cant's see the letters, I printed an AutoCad drawing to PDF and the PDF looks OK on the

    I need to know why this crosshatching appears over the text when I print the PDF

    If you use the same Adobe Reader versions with the same PDF on Windows 7 and XP, then I would expect the outcome to be the same.
    Is this a local or online PDF?
    If local, is the file really exactly the same?
    If online, in what browser?

  • Print just what is typed in the text field without printing the text fields

    Hello,
    I'm trying to print a form after I filled in the text fields, but would like it to print just what I typed in the field, not the text field and the color in the text field. I use CS3.
    Any help would be appreciated!

    Hello Teddy and wellcome to the group!
    If you want to change fonts or other things then you might need to use the PrePrint method. What I normally do is select PrePrint from the "Show" section in the Script Editor (If you do not have it go to the toolbar at the top, Windows, and select Script Editor). After you select PrePrint you can now either type the name of the subform and field you want to change (or you can put your cursor in the Scripting Dialog box, hold CTRL and then select the field with your mouse) and then type in the JS to change the font. it is something like TextField1.fillcolor = "255, 255, 255"; (that changes the background fill to white). You can also replace fillcolor with font or border to change the color of the font or the border. I put a link to an Adobe website that goes over JS color changes below. You just need to add a PrePrint method for each field that you wish to remove the necessary highlighting on. Then once the user either hits a Print button that you have on the form or uses CTRL+P to print the form it will remove any highlighting.
    Now On the Text Field not printing itself that I am not sure what you are asking for. Are you asking for the caption not to print or for there not to be a box around the data that is entered? If you do not want to have a box surround the text field that is in the Object section of the field (see image below). You just need to select None if you just want the text. If you want to change that with JS I put another link below that has the code to change the border color to white and the user cannot see it. If you do not want the caption to print the only method is to delete the caption from the text field and replace it with static text that can be hidden, but I am assuming that is not what you are talking about (correct me if I am wrong though).
    http://partners.adobe.com/public/developer/en/livecycle/designer/pdfs/ChangingFieldAndSubf ormBGColors.pdf
    https://forums.adobe.com/thread/1409617

Maybe you are looking for

  • Can I clone my desktop windows 7 into apple tv

    Hi I would like to clone my desktop pc / lap top (using windows 7) to big screen TV through Apple tv is that possible, if so pl help me. Cheers Fazil

  • Images in web forms R6.0

    Leaving the client/server configuration and entering the true three-tier solution should be easy, says oracle. Then tell me how to "Create a container class extending then VBean" to invoke forms 6 to show a blob-stored jpg-file. Has anyone done it al

  • Read custom field's values in GRAC_UIBB_ACCESS_REQUEST

    Hi All, We have added new fields in webdynpro component: GRAC_UIBB_ACCESS_REQUEST and displayed new fields in front end. Enhanced above webdynpro component but not able to read those new field's values inside the enhancement, as the context doesn't h

  • Can each page of an indesign booklet have its own set of layers

    i am very VERY VERRRRRY new to indesign. i was basically thrown into the program to keep the project from sinking when a designer quit on me! so im trying to give each page of my catalog its own set of layers. is this even possible. right now the lay

  • Acrobat bookmark settings not saved

    FM 9.0p255, Acrobat 9 Pro Extended 9.4.1 – every time I go to save a book as .pdf, I now have to respecify the bookmark options. Don't remember noticing this before, and it would certainly have irritated me enough to prompt a posting! What's going on