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

Similar Messages

  • 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.

  • Problem with Printing the Billing date...

    Hi Experts...
    Here im facing the problem in printing the billing date.
    The scenario is as follows.
    The posting date of Billing is 10.10.2008
      The document date of Billing is also 10.10.2008.
    At the time of printing the Billing document it is taking another date otherthan 10.10.2008,where it should be 10.10.2008.
    What modifications should i do to rectify the problem.
    Please advice.
    Regards,
    Y P.

    Prasad,
    Ask your ABAPer do debug and find out what date (Table-Field) is used in the Invoice Output program. You will know the reason and if you think that the date being used is incorrect, you can ask your ABAPer to change it to VBRK-FKDAT which is the billing date.
    Chandan

  • Problem with printing the sub totals

    Hi,
    I am having a problem with smart forms in printing the line items of invoice.
    I need to print the sub total of each page and need to display the sub total in the footer, with the caption 'Balance C f/w'. It works fine in some cases.
    In some cases, the sub total is getting printed wrongly, because its adding the amount of the next page's first line item also. I checked the form page by printing SFSY-PAGE along with the line item's text. It's observed that, the vlaue of SFSY-PAGE for the first line item's  displayed in the second page is '1'. Due to this, the amount for this line item also is getting calculated with the sub total of the previous page.
    Could you please suggest a solution for this problem?
    Thanks & Regards,
    John

    Hi,
    In smartforms, in the general attributes of the FIRST page the Mode for the page counter should be 'Initialize counter' and for the NEXT page it should be 'Increase counter'.
    Please check this in your smartform.
    Regards,
    Ram

  • Problem with printing the code

    Hi ,
    I m having problems in printing my source code . I use emacs as a text editor. Is there any settings that need to be made before printing . Because when i try to print it didn't print my whole code. And when i try to print it from some where else it gives me error saying printer not found on LPT1. Is it something about the port or what. Plz tell me about it ASAP , because i need to submit my project.
    Bye
    Waiting for reply

    Hello gotchya11,
    If you are using a Unix environment, you can use the "lp" print command to send a document to printer. The "-d <device name>" flag is where you specify which printer to sent the document to. You can do a
    "man lp"
    from the command line to get more info on how to print. Perhaps you need to specify the destination where the file is to be printed. What you can do if you need to print the doc is to just copy and paste your code into a text editor and print from some other program if you are running Solaris CDE or Windows.
    Hope this helps,
    Ming
    Developer Technical Support
    http://www.sun.com/developers/support

  • Problem with printing the correct "ical" pages.

    G'day
    I have only recently started using "iCal", on the cloud, having upgraded my laptops to "Lion" and my iPhone to "5", so that I have NOT experienced any of the "syncing" problems of which I have read elsewhere.
    BUT, I do have an irritating problem, the solution to which, being a long-term Mac user, should be obvious.
    The problem stems fronm the fact that I am located on the east coast of Australia, and my laptops know this.
    The first, really daft, thing that I did was to create a whole lot of iCal entries, in iCloud, without noticing that the default timezone was "Pacific".
    So, OK, I fixed that by going into my ID on iCloud and changing the timezone, and then editing every single event that I had entered at that point in time.
    So, I then thought that I had beaten the beast, because I had only been printing "Weekly" calendars, which were OK.
    Today, I decided to print some "daily" calendars, and the system WILL NOT PRINT THE CORRECT DATE.
    My iCal entries are mainly to do with a trip that that starts on 1st August this year. I bring up iCal on the Mac, go to the print page, select 01 Aug 2012, and it prints 31 July 2012.
    This happens whether I tick the "Timezone" preference in iCal on the Mac, or not.
    What else should I do?
    Dave the Desperate

    Hi Srikanth,
    In the second page you can insert a command to set it to goto page 3,and an additional event in the command (only after the end of main window).
    As soon as the main window ends in the second page...u will get the third and rest of the pages.
    Keep the goto next page in PAge 1 as Page2
    and in Page 2 as Page 2.

  • Problem with printing the structure in ECC 6,0

    Hi Everybody,
    I'm working in upgrade project.
    in 4.7 version, directly trying to print the work area and assign to some other fields.
    Eg: write: Mara.
    text = mara.
    but in 6.0, its not allowing to assign directly like this.
    \[removed by moderator\]
    Thanks in advance.
    Regards,
    JaganMohan.
    Edited by: Jan Stallkamp on Jul 29, 2008 6:54 PM

    Now, you have to write the individual fields inside the mara stucture.
    Regards,
    ravi

  • Problem with printing the smrtform

    Hi experts,
        I want to print material number through smartform. i have a internal table containing material number and its quantity. I want to print particular material number for number of  quantity times. it means if i have 3 rows in internal table ,  that means 3 material numbers are there and  number of quantity is 50 for each material . so i want to print each material number for 50 times.

    Hi Rupesh,
    You can try following code.
    Lets take an example of just one material number in your internal table.
    what you can do here is  create two similar tables with quantity &  material number.
    Loop at itab.
    here capture the quantity field.
    do < quantity  times >
    append the material numbers to the second internal table.
    enddo.
    endloop.
    This way you can build an internal table with material numbers for total number of quantities.
    Then use this table in your smartform.
    Hope this helps.

  • Problem with printing the pages due to main window

    hi experts ,
       in my requirement i have 4 pages in smart form.It takes quotation number as input and dispaly all the contracts.
    1 potrait
    2 potrait
    3 landscape
    4 landscape
    i have used a main window in the second page contains 2 windows for printing address then
    one main window for printing contracts, and systems info in two tables .
    i have used a main window in the 4 th page too for printing some item details equipment list.
    both main windows having same width.
    i am getting  1 st & 2nd pages only as o/p if i mention 2nd page in the next page field of first page .
    i am getting 1 st  3 rd , 4th , 5th ........pages if i mention 3 rd page in the next page fileld of first page .
    i didn't use any extra page to populate if  2nd page is filled completely    .
    please guide me  .
    Thanks & regards.
    Srikanth

    Hi Srikanth,
    In the second page you can insert a command to set it to goto page 3,and an additional event in the command (only after the end of main window).
    As soon as the main window ends in the second page...u will get the third and rest of the pages.
    Keep the goto next page in PAge 1 as Page2
    and in Page 2 as Page 2.

  • PROBLEM WITH FETCHING THE TEXT FROM  HEADER DATA

    Hi,
    plz give me the solution.
    TYPES:BEGIN OF WA_TLINE,
            TDFORMAT TYPE TLINE-TDFORMAT,
            TDLINE(132) TYPE C, "TLINE-TDLINE,
           END OF WA_TLINE,
         BEGIN OF WA_STXH,
            TDOBJECT TYPE RSTXT-TDOBJECT,
            TDNAME TYPE STXH-TDNAME,
            TDID TYPE STXH-TDID,
            TDSPRAS TYPE STXH-TDSPRAS,
          END OF WA_STXH.
    DATA : OBJECT(10) TYPE C,
           it_inline  TYPE TABLE OF WA_TLINE with header line,
           IT_LINE TYPE TABLE OF WA_TLINE WITH HEADER LINE,
           IT_STXH TYPE STANDARD TABLE OF WA_STXH WITH HEADER LINE,
           IT_HEAD TYPE THEAD.
    *data:it_tdline like  table of tline with header line.
    PARAMETERS:PA_VBELN TYPE VBELN_VF.
    START-OF-SELECTION.
    SELECT TDOBJECT TDNAME TDID TDSPRAS FROM STXH INTO CORRESPONDING FIELDS OF TABLE IT_STXH
      WHERE  TDNAME = PA_VBELN.
    MOVE IT_STXH-TDOBJECT TO OBJECT.
    IF SY-SUBRC EQ 0.
    CALL FUNCTION 'READ_TEXT_INLINE'
      EXPORTING
        ID                    =  IT_STXH-TDID
        INLINE_COUNT          =  '1'
        LANGUAGE              =  IT_STXH-TDSPRAS
        NAME                  =  IT_STXH-TDNAME
        OBJECT                =  'VBBK'
      LOCAL_CAT             = ' '
    IMPORTING
      HEADER                =  it_head
      TABLES
        INLINES               = it_inline
        LINES                 = it_line
    EXCEPTIONS
      ID                    = 1
      LANGUAGE              = 2
      NAME                  = 3
      NOT_FOUND             = 4
      OBJECT                = 5
      REFERENCE_CHECK       = 6
      OTHERS                = 7
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDIF.
    write:/ it_inline.
    iam using this program but it will shows the error  object is not found but it will comes in itab when u pass the data from itab to function module it will shows the error.
    I will give the nuts.
    Regards,
    Venkat

    Hi Venkat,
    This is working fine for me.
        CALL FUNCTION 'READ_TEXT_INLINE'
          EXPORTING
            id                   = '0001'
            inline_count    = '1'
            language        = 'D'
            name             = '0000005462'
            object            = 'VBBK'
            local_cat        = ' '
          IMPORTING
            header           = it_head
          TABLES
            inlines            = it_inline
            lines               = it_line
          EXCEPTIONS
            id                    = 1
            language         = 2
            name              = 3
            not_found        = 4
            object             = 5
            reference_check = 6
            OTHERS          = 7.
        IF sy-subrc NE 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-      msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDIF.
      WRITE:/ it_inline.
    Regards
    avi.....

  • Problem  in Printing the ALV list

    Hi,
       I have one problem with printing the ALV list. While printing the ALV list(thro Print Icon on application Tool bar) ,Fist page of my print out contains some other inforamtion.
      inforamtions included two tables
      first table  contains Sort Criteria, Ascdg, Descnd, Subtotal  columns.
      And second table contains Data statistics , number of
    columns.
    But from Second page onwards , my alv list printed correctly .
      How can i avoid the First page inforamtion and
          what is the Reason of coming like this?
    Thanks,
    Neptune.M

    I assume you are using function module Reuse_alv_grid_display or reuse_alv_list_display for ALV.
    If this is the case, there is a parameter called IS_PRINT that you need to supply while calling the function module.
    you can for exapmle declare
    data:
    printstruc type SLIS_PRINT_ALV.
    printstruc-NO_PRINT_LISTINFOS = 'X'.
    call function 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
    IS_PRINT = printstruc
    There are many other flags in is_print structures that you can use to manipulate the printing.
    Cheers!

  • 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?

  • I had a problem with print preview of billing document.

    HI all,
    I had a problem with print preview of billing document which contains two output types ZR1 ZR2..
    For the footer text of billing document I maintained the font size as 7,5 pts, But when i go for print preview from output type ZR1 the font size of footer text is very small and looks good for output type ZR2.
    If i change the print options-->logical destination of output type ZR1 same as Output type ZR2, the footer text looks good.
    I think there is some issue with logical destination in print options for the output type ZR1, how can i resolve  it.

    hi,
    for both the output types , r u using same sapscript or smartform?
    if yes then, u can control it in output options of smartform and also in sapscript , you can control through if condition.
    and if differect sapscript or smartform then you should not get such problem.
    you can check the sapscript or smartfrom in TNAPR table.

  • Problem with printing from Acrobat Reader XI

    SInce I installed Acrobat Reader XI I have got problems with printing out pages. The text starts a bit down (2 cm) on the paper, resulting that the last part of the text on the page will be missing. And the missing part does not follow on page 2, it just don´t comes out!
    It doesn´t matter what settings i click in on the print setting page in Acrobat Reader, it always gets the same result.
    Does anyone know what can be the problem?

    No files appeared in C:\Users\Pavilion\AppData\Roaming\Adobe\Adobe PDF\Settings but they did appear in Distiller.
    I tried to copied them from C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Settings, but found they were already there.  I copied them by adding -COPY before .joboptions in the name.  Now they appeared in  Printing Preferences with the -COPY added.
    I tested a print from Word (using File / Print), but was not prompted for the filename or location.  I checked my entire system and couldn't find the PDF file anywhere.  I tried changing the Port to Desktop\*.pdf using Printer Properties, but that didn't work either.
    I was able to successfully use the Acrobat menu item in Word & Excel to create a PDF but it automatically created the file on the Desktop without an option to change the filename.
    After several days and hours, I gave up and installed Acrobat X on the W7 computer.  I can still use Acrobat XI on the W8 computer.  So be it!
    Thanks anyway for your attempts to help.

  • Problem with print photo 13x18

    hi i have a problem with print photo (13x18) size it cut in the end of photo i use hp photo creations but if choose 100%size or full screen  same result  please what can i do;  i am disapoint to buy this printer if photo print so

    Cornelia-I, I used "single/image contact sheet" and there is a Lightroom
    Template for 2x2 cells.  I modified this a little to make the cells smaller
    to provide room for the captions and margins for hole punching and binding
    the sheets.
    No, I surely did not type in each caption.  The captions were Title plus
    Caption taken from the metadata plus a comma and # sign preceding the
    filename which was a date/sequence number.  I was printing four different
    images on each page and 36 images total so there were nine pages of the
    booklet.
    I didn't try the idea of switching the Photo Info option off and back on to
    the custom package because I had already created a custom preset and as soon
    as I discovered that all it needed was to have a period added or removed at
    the end of the line each time, it was easy to simply switch back and forth
    between the two text presets which was doing the same thing you recommended.
    Whole job was simple once I discovered that the problem was simply that I
    needed a new version of the text string every time I printed and couldn't
    simply keep using the same one over and over.  The time wasted was lost
    trying to figure out what was causing the lines to suddenly become truncated
    when previously they had been there.  Which is why I wrote it up so others
    need not waste that time if they want to do this.

Maybe you are looking for