Help with printing in Java

Hi,
I am making a simple printing application.
I need to print the contents of a JTextArea, I have the following
class: (I won't put the whole class code because is very long)
public class PrintExampleClass implements Printable {
this class has the following method: (I assume this method does the printing work)
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());
componentToBePrinted.paint(g2d);
return(PAGE_EXISTS);
note: componentToBePrinted is the JTextArea.
Everything works fine, the problem is that only the first page is printed, and sometimes
the text inside the JTextArea is huge, so I need to print the whole text.
How can I print all the pages?
thanx in advance

I've done this last week. Your print method returns NO_SUCH_PAGE if the pageIndex value is over 0.
You must return PAGE_EXISTS instead if the signified page does exist and want the page to be rendered.
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());
componentToBePrinted.paint(g2d);
return(PAGE_EXISTS);

Similar Messages

  • Help with Print Layout Designer

    Hi all,
    I'm not sure if I should post this here or not, I already posted it in the Business One Forum.  Moderator(s)  if this is not the proper place please delete it and let me know that it is not the appropriate venue.
    I need some help with Print Layout Designer.  I am running 2005A SP01, and my customer wants a modification to the Sales Backorder Report.  They want to add the column "In Stock" to both the report as displayed on the screen and the printed document.  The report rendered to the screen has the In Stock, but it is not checked as visible.  I check it and In Stock shows up as designed.  The part I am having problems with is the printed document. I opened the PLD from the Backorder Report, and saved it under a different name.  I resized some of the columns in the repetitive area (header and data) to make room for the In Stock column.  I CAN add the text field Instock as free text and enter "In Stock" as the content.  I looked at the "backorder" column in the PLD, and it is a text field with the source System Variable and the variable is 109.  I would assume that all I need to do in my added column is to set the source to System Variable and enter the variable number.  That is the problem; I can't find the variable number for that column.  I looked on the report rendered to the screen with system information on and the variable is "3 #000027825,OnHand".  I looked at the Back Order column of the report rendered to the screen and the variable is "3 #000028725,OpenCreQty".  I found a spreadsheet that is supposed to contain a list of system variables for 2007A, but the document type for this report is BRDR and that document type does not appear in the list of document types in that spreadsheet.  I looked for a similar spreadsheet for 2005A SP01 but didn't find one.  I DID find a document "How To Customize Printing Templates with the Print Layout Designer".  According to that document, I should be able to get the system variable from the report rendered to the screen with System Information turned on.  Can anyone help?
    TIA,
    Steve

    I haven't dealt with this before so I can't be certain, but here are my thoughts.
    The Backordered Qty is probably a calculated field, so that's why it's a system variable. The In Stock is a defined field, so you probably can use the file and field number, OITM, OnHand. I would look at maybe the stock number or description to see how those are setup on the form instead of the backordered qty field.

  • I need help with printing labels.  please

    I need help with printing labels.  thanks in advance

    Welcome to Apple Support Communities.
    In Address Book, first select a name or group of names to print.
    Then File, Print, select Style, Mailing Labels, then Layout to select a specific target label (such as an Avery number), or define your own...

  • Im DROWNING! need help with a simple java assignment! plz someone help me!

    i need help with my java assignment, with validating a sin number. easy for must who know java. im drowning... please help!

    You will need to store each digit of the social insurance number in a field of its own. To validate the entry you will:
    1. Multiply the 2nd, 4th, 6th and 8th digit by 2.
    2. If the product of any of the four multiplications result in a value greater than 9, add the two resulting digits together to yield a single-digit response. For example 6 * 2 = 12, so you would add the 1 and the 2 to get a result of 3.
    3. Add these four calculated values together, along with the 1st, 3rd, 5th, and 7th digits of the original number.
    4. Subtract this sum from the next highest multiple of 10.
    5. The difference should be equal to the 9th digit, which is considered the check digit.
    Example of validating S.I.N. 765932546
    1st digit 7
    2nd digit (6*2 =12 1+2=) 3
    3rd digit 5
    4th digit (9*2 = 18 1+8 =) 9
    5th digit 3
    6th digit (2*2 = 4) 4
    7th digit 5
    8th digit (4*2 = 8) 8
    Total 44 next multiple of 10 is 50
    50-44 = 6 which is the 9th digit
    Therefore the S.I.N. 765932546 is Valid
    ********* SIN Validation *********
    Welcome - Please enter the first number: 120406780
    Second digit value multiplied by 2 4
    Fourth digit value multiplied by 2 8
    Sixth digit value multiplied by 2 12
    Eighth digit value multiplied by 2 16
    Value derived from 6th digit 3
    Value derived from 8th digit 7
    The total is 30
    Calculated digit is 10
    Check digit must be zero because calculated value is 10
    The SIN 120406780 is Valid
    this is my assignemtn this is what i have! i dont know where to start! please help me!
    /*     File:     sinnumber.java
         Author:     Ashley
         Date:     October 2006
         Purpose: Lab1
    import java.util.Scanner;
    public class Lab1
              public static void main(String[] args)
                   Scanner input = new Scanner(System.in);
                   int sin = 0;
                   int number0, number1, number2, number3, number4, number5, number6, number7, number8;
                   int count = 0;
                   int second, fourth, sixth, eighth;
                   System.out.print("\t\n**********************************");
                   System.out.print("\t\n**********SIN Validation**********");
                   System.out.print("\t\n**********************************");
                   System.out.println("\t\nPlease enter the First sin number: ");
                   sin = input.nextInt();
                   count = int.length(sin);     
                   if (count > 8 || count < 8)
                   System.out.print("Valid: ");
         }

  • Looking for Help with Hyperion to JAVA

    I am looking for help with connecting Hyperion to Java. We are in Maryland but would be willing to work out something for remote consulting. If you have experience with connecting web services, hyperion, and Java and would be interested in about 80 hours of consulting please contact me at:[email protected] x4846

    Hi,
    From your description, you want to achieve the following goal:
    Configure Exchange to filter the attachments if the size is over 10 MB and store it in a public folder, and then forward the email to Salesforce.
    Based on my knowledge, I'm afraid that it can't be achieved. Exchange can filter messages with attachments, but it couldn't store these attachments on public folder automatically. Also, I don't see any transport rule can do it.
    Hope my clarification is helpful.
    Best regards,
    Amy Wang
    TechNet Community Support

  • Need help with Printer Setup conventions

    I can't get my Brother printer to print from one computer--but it prints okay from the other computer on my network. I need to know the conventions for the Printer Setup Utility.
    There's a checkbox by every printer on the list. What does it mean when the checkbox is grayed out?
    Some printer names appear in bold. What does that mean?
    Thanx.

    Thank you for your reply. I appreciate your help in this and just want to understand what you're saying.
    As I say, the printer is displayed in the print dialog box but the checkbox is grayed out. I'm assuming that when you say "...it can't find/see them now," you mean the print dialogue can't see them (the drivers). Your last sentence confuses me. You say, "Do you maybe have Printer Sharing enabled & they aren't actually directly connected? If so you have to reboot after turning it off." A little confusion about your antecedents here. What isn't actually connected? The printer? So I have to reboot after turning it off, "it" I suppose is the printer, is that right? I will try that. So turn printer off, reboot, turn printer on. Right?
    I will describe my problem. l thought that if I understood why the checkbox was grayed out I might see what my problem was. If you want me to start another topic I can do that.
    Problem: I have a network with 2 computers and the Brother
    multifunction fax/printer. I'm using an Apple airport hub. The printer
    and one computer (Mac tower) are connected to the airport base via
    ethernet. The 2nd computer (Apple laptop) is on the wireless network.
    Until recently i could print from both computers. Now I can't print from
    the tower. But I can still print from the laptop.
    When I try to print from the tower I get an error message that says, "Cannot print from current printer." I have rebooted, reinstalled printer drivers, checked cables, deleted printer from printer list and re-added printer all to no avail. But as I say, I can still print from the laptop which is using Airport. So the printer prints, the hub connects to the printer okay (ethernet) and I know the tower connects to the hub (I can ping the printer okay from the tower.)
    I am conversing to Brother support via email and their first suggestions I have already tried. Perhaps there's some problem in the network, but I can't figure it out. Worse yet, now when I go to the Network preferences I get an error message which says, "Your network settings have been changed by another application." THIS ERROR MESSAGE WON'T GO AWAY! I can click 'okay' but it reappears. I have to force quit the System Preferences to get out. If you can help with any of these problems I surely appreciate it.

  • Help with a SIMPLE java thing

    I've only got ONE handful of hair left.
    I'm trying to build a series of dropdown boxes; a day dropdown (Mon, Tue, Wed...), a month dropdown (Jan, Feb, Mar...), a year dropdown, hour dropdown, minute dropdown, and an am/pm dropdown.
    I think I want to build my dropdowns using "for" loops something like this:
    for (i=0;i<12;i++) {
    myStringBuffer.append("<option>" + [someUnknownFunctionThatReturnsTheFirstThreeLettersOfTheMonth(i)] + "</option>")
    I've been trying to mix up various combinations of Date objects (most date functions seem to be depreciated), Calendar Objects, DateFormat Objects and SimpleDateFormat Objects but nothing seems to want to perform the function that I need.
    I've had iffy success creating a calendar object, setting the Month to "i", using the getTime function to return a Date object which I can then pass to the SimpleDateFormat object using the .format(Date) function, after setting the pattern to "EEE", but it seems like just an incredibly complicated way to do what ought to be a simple function...i.e. convert a number 0-11 (or 1-12, I'm not picky) into the name of a stinking Month! Arrgh.
    If anyone can help, I thank you.

    I've done that before, so i'll share it with you.
    import java.text.SimpleDateFormat;
    import java.text.DateFormatSymbols;
    import java.util.Calendar;
    import java.util.Date;
    public String createListOfMonth(String pName) {
    StringBuffer sbMonth = new StringBuffer();
    DateFormatSymbols fm = new DateFormatSymbols();
    String[] arrMonth = fm.getMonths();
    sbMonth.append("<select name=\"" + pName + "\">");
    sbMonth.append("     <option value=\"\">Month</option>\n");
    for (int i=0; i<arrMonth.length; i++) {
    if (!arrMonth.trim().equals("")) {
    String sValue = "0000" + (i + 1);
    sValue = sValue.substring(sValue.length() - 2);               
    sbMonth.append("     <option value=\"" + sValue + "\">" + arrMonth[i] + "</option>\n");
    sbMonth.append("</select>");
    return (sbMonth.toString());
    You can manipulate the symbol (either for months, days) using different locale. You can see the API for java.text.DateFormatSymbols in Java2 SE.
    Regards,
    Hariyanto

  • Need some help with printing Templates

    Hi All,
         So I was hoping for a bit of help. I am currently doing all illustrator work for my new job. I have not been on the program in a long time and the version I am using is CS4. I have been creating brochures and flyers all A4 size and i have hit a bump in the road. I need a 6pp A4 Z folded (Inside) and 6pp A4 Z folded (outside) template. I Have been using the A3 folded to A4 guides to great affect for a two page brochure. But i cannot for the life of me find a template guides for 6pp A4 brochure.
    This was the best i could do, its a pdf but I prefer working with the guides. I have just been downloading the previous templates from commercial printing websites. I found one that was right but not compatible with CS4.
    Any help with finding one or any ideas on a path to take would be greatly appreciated.

    Why don't you just setup the file you need?
    Create your guidelines and there you go.

  • Need help with long term Java problems

    I've been having problems with Java on my computer for about a year now, and I'm hoping that someone here can help me out.
    Java used to work fine on the computer when I first got it (a Dell laptop) and I hadn't installed anything myself. But then one day it stopped loading Java applets, and hasn't worked since. By this, I mean that I get the little colorful symbol in a box when I try to play Yahoo games, use the http://www.jigzone.com site, go to chat rooms, etc. Java menus on websites like http://www.hartattack.tv used to work still, but lately they've been giving me that symbol too.
    I've tried downloading a newer version of Java, but nothing I do seems to work, and I don't know of anything I did to trigger it not working. I'm hoping there's a simple solution to this, and I'm just dumb.
    Thanks.

    This might be way off, but it's something that's tripped me up in the past:
    If you are using Sun's Java plugin, the first time you go to a site that has a particular Java applet, you may be asked to approve/reject a security request.
    If you have clicked on any other windows while the request is first being loaded (which can take some time, because this is swing based), then the security dialog box does not pop to the top of the window stack, and doesn't add an entry into the task bar.
    It appears that Java just doesn't work, but it's actually waiting for you to click "Yes". You can check this by hitting alt-tab and seeing if the Java coffee cup icon is one of the options.
    - K

  • Help with printing hard copy from Acrobat PDF

    Copy created in InDesign and printed to Adobe PDF is OK on screen but printing hard copy with random chunks of text missing. Same on both my printers, doesn't happen with doPDF. Any ideas? Thanks

    I suspect that what you are asking is simply to print to a new PDF with print as image selected. You can also save as an image file and then open the images as a new PDF.

  • Need Help with Print a Report

    Hi,
    I am building a database application in Java and now i need to print some reports ....
    I need to get the data from the database .. do some calculations , and then print in on paper.
    I checked online and got some tools like JasperReports, jfreereports, ReportCat, etc. so I was wondering if somebody can suggest whats the best.
    In my report I will have to print more than one table on one page.
    for example:
    if I have 4 Invoices. then i will have 4 tables .. one for each invoice.. and each table will contain
    the elements for that Invoice.If all can't fit on one page then it needs to go next page.
    I would like to do all this stuff in Java without using any reporting tool ... but I am not really sure how this can be
    done .. can someone give me an idea ... as per how this can be done .. will really appriciate all the help.
    Thanks in advance,
    sandsouza

    Hi,
    Can somebody please help me with this.
    Thanks in advance
    sandsouza

  • Help with printing from an array

    hello there, looking for help. Basically i have read a text file into an array. I can print a sentence from the array using startsWith()...if i take that code out, and just put in the last part:
    while(!(words.trim()).startsWith("slightly")) {
         System.out.println(i + ":" + words[i] + ":");
         i++;
    this basically prints out the whole text file until it reaches the word slightly. I want to print out text that is in between two words. Now i can stop printing with this , any suggestions on how i can tell it to start printing when it finds a word....
    public static void main( String[] args )
         int i = 0;
    // will store the words read from the file
    List<String> wordList = new ArrayList<String>();
    BufferedReader br = null;
    try
    // attempt to open the words file
    br = new BufferedReader( new FileReader( "ireland.txt" ) );
    String word;
    while( ( word = br.readLine() ) != null )
    // add the read word to the wordList
    wordList.add( word );
    } catch( IOException e ) {
    e.printStackTrace();
    } finally {
    try {
    // attempt the close the file
    br.close();
    catch( IOException ex ) {
    ex.printStackTrace();
    String[] words = new String[ wordList.size() ];
    // wordList to our string array words
    wordList.toArray( words );
    System.out.println(" Returning line ");
    // loop and display each word from the words array
    /*while(i < words.length )
         String tempWord = words[i].trim();
         //area
         if (tempWord.startsWith("'''Loc"))
              System.out.println(i+":"+ words[i]+":" );     
         i++;
    /*while(!(words[i].trim()).startsWith("slightly")) {
         System.out.println(i + ":" + words[i] + ":");
         i++;

    This may help, it looks like the same assignment:
    http://forum.java.sun.com/thread.jspa?threadID=5144211
    Yeah, and it's from the same guy.
    Thanks (NOT) for posting yet another thread about the
    same problem, tras.D'OH! I didn't even notice that. In what ways were the answers you got in the other thread insufficient?

  • Help with a simple Java program

    I'm making a sort of very simple quiz program with Java. I've got everything working on the input/output side of things, and I'm looking to just fancy everything up a little bit. This program is extremely simple, and is just being run through the Windows command prompt. I was wondering how exactly to go about making it to where the quiz taker was forced to hit the enter key after answering the question and getting feedback. Right now, once the question is answered the next question is immediately asked, and it looks kind of tacky. Thanks in advance for your help.

    Hmm.. thats not quite what I was looking for, I don't think. Here's an example of my program.
    class P1 {
    public static void main(String args[]) {
    boolean Correct;
    char Selection;
    int number;
    Correct = false;
    System.out.println("Welcome to Trivia!\n");
    System.out.println("Who was the first UF to win the Heisman Trophy?\n");
    System.out.print("A) Danny Wuerffel\nB) Steve Spurrier\nC) Emmit Smith\n");
    Selection = UserInput.readChar();
    if(Selection == 'B' | Selection == 'b')
    Correct = true;
    if(Correct == true)
    System.out.println("\nYou have entered the correct response.");
    else
    System.out.println("\nYou missed it, better luck next time.");
    System.out.println("(\nHit enter for the next question...");
    System.in.readLine();
    Correct = false;
    System.out.println("\nWhat year did UF win the NCAA Football National Championship?\n");
    number = UserInput.readInt();
    if(number == 1996)
    Correct = true;
    if(Correct == true)
    System.out.println("\nYou have entered the correct response.");
    else
    System.out.println("\nYou missed it, better luck next time.");
    Correct = false;
    System.out.println("\nWho is the President of the University of Florida?\n");
    System.out.println("A) Bernie Machen\nB) John Lombardi\nC) Stephen C. O'Connell\n");
    Selection = UserInput.readChar();
    if(Selection == 'A' | Selection == 'a')
    Correct = true;
    if(Correct == true)
    System.out.println("\nYou have entered the correct response.");
    else
    System.out.println("\nYou missed it, better luck next time.");
    }

  • Desperately need some help with client-server java programming

    Hi all,
    I'm new to client server java programming. I would like to work on servlets and apache tomcat. I installed the apache tomcat v 5.5 into my machine and i have sun java 6 also. I created a java applet class to be as a client and embed it into an html index file, like this:
    <applet code="EchoApplet.class" width="300" height="300"></applet>However, when I try to run the html file on the localhost, it print this error: classNotFoundException, couldn't load "EchoApplet.class" class. On the other hand, when I open the index file on applet viewer or by right clicking, open with firefox version 3, it works.
    I thought that the problem is with firefox, but after running the applet through the directory not the server, i found that the problem is not any more with firefox.
    Can anyone help me to solve this problem. I'm working on it for 5 days now and nothing on the net helped me. I tried a lot of solutions.
    Any help?

    arun,
    If the browser is going to execute $myApplet, first it must get the $myApplet.class from the server, right?
    So it follows that:
    1. $myApplet.class must be acessible to server, and
    2. the server must know exactly where to find $myApplet.class
    So, the simplest solution is to is put the $myApplet.class in the same directory as the HTML file which uses it... then your applet tag is simple:
      <applet height="200" width="400" code="$myApplet.class" ></applet>* The height & width attributes are required
    * Note the +.class+ is required in the code attribute (a common mistake).
    * This works uniformly (AFAIK) accross all java-enabled browsers.
    * There are incompatibilities with the codebase attribute. Poo!
    Cheers. Keith.

  • Help with printing out the # of quarters, nickels, dimes, and etc... using

    Hi, im new to java and im using a program called blue j.
    anyway heres my question.
    , I recommend you dont do the program for me, but rather help gear me in the right direction of things.
    In this program they want me to have it print out the # of dollars,quarters,nickels,dimes, and pennies.
    They have provided me with a base program to start off with which is this.
    import chn.util.*;
    public class ComputeChange
       *  The main program for the Change class
       * @param  args  The command line arguments - not used
      public static void main(String[] args)
        double purchase, cashPaid, temp;
        int change, remainder, dollars, quarters, dimes, nickels, pennies;
        ConsoleIO keyboard = new ConsoleIO();
        System.out.print("Enter amount of purchase --> ");
        purchase = keyboard.readDouble();
        System.out.print("Enter amount of cash paid --> ");
        cashPaid = keyboard.readDouble();
        temp = cashPaid - purchase;
        dollars = (int) temp;
        temp = temp - (int)temp + 0.0000001;
        change = (int)(temp * 100);
        System.out.println();
        System.out.println("$" + dollars + "." + change);
    }Ive been given the amounts 23.06 for amount of purchase
    and 30.00 for the amount paid. that should give me the difference of $6.94
    It should print out the amount of change as the following
    6 dollars
    3 quarters
    1 dime
    1 nickel
    1 penny.
    IVe tried a few methods for printing out the # of each coin type, but i simply dont get how they are using temp or what type of funciton i need to follow. Any hints or pointings in the right direction would help. Since i need to learn this.
    Thanks a lot and i hope i can get some tips. !
    ~Jbinks

    And here's my contribution to the scratch batch... :o)
    class Coins {
        private java.util.Map<Coin, Integer> count = new java.util.HashMap<Coin, Integer>();
        enum Coin {
            DOLLAR(100), QUARTER(25), DIME(10), NICKEL(5), PENNY(1);
            private final int value;   
            Coin(int value) { this.value = value; }
            public int value() { return value; }
        public Coins(int centsValue) {
            for (Coin c : Coin.values()) {
                count.put(c, centsValue / c.value());
                centsValue %= c.value();
        public void display() {
            for (Coin c : Coin.values()) {
                System.out.println(c + ": " + count.get(c));
    public class CoinsDemo {
        private static java.util.Scanner keyboard = new java.util.Scanner(System.in);
        public static void main(String[] args) {
            int price = getPennies("Enter amount of purchase --> ");
            int paid = getPennies("Enter amount of cash paid --> ");
            new Coins(price - paid).display();
        private static int getPennies(String prompt) {
            System.out.print(prompt);
            double d = keyboard.nextDouble();
            System.out.println();
            return (int)(d * 100);
    }

Maybe you are looking for

  • Bootcamp "no bootable device" Option key not working

    Ok recently rebuilt 2 older "Intel Core Duo" Mac Mini's with SSD drives. They work great and have been flying, however on one of them I wanted to setup BootCamp so that I could run Win7 Pro on it as well. So here is what I did... - When I first built

  • ICR Process 003 - Unassigned documents

    Hi, We have been live with the ICR module for three accounting periods now and have just encountered a serious issue.  There is an instance on one company where all the Payables documents between two particular trading partners are displayed in FBICR

  • Interface between Computer-aided design (CAD) and Businees One

    Hi, I would like to know if someone as already have to link BOM from CAD software in Business ONe How can it works, using DTW, with a program ?

  • Config need for T. Code PA30, PA71

    Dear Experts, I have a following Client requirement as like, 1. There are two SAP User (AS User 1 and User 2)  for SAP Payroll. requirement is whenever "User 1 " will create a record for IT0008, 0014 , 00015 and 0057 through PA30 or PA71 that record

  • System Functions !!!!!Please help

    Hi Experts, I was copying a program from ECC sandbox to the SAP BW sandbox but the following piece of code does not work in the BW sandbox. CALL 'SYSTEM' ID 'COMMAND' FIELD l_cmd ID 'TAB' FIELD it_list-sys. This was working in the R3 environment. can