Help for printing textarea

hi
How can I print a long line.
for exmple
0123456789012345678901234567890123456789012345678901234567890123456789
if i print a textarea with this content i get a printout that looks like this:
012345678901234567890123456
do i have to set anything so that the line is wrapped??
my code looks like this:
1st part:
public class Ta extends JTextArea implements Printable{
     public Ta(){
          super();
          this.setPreferredSize(new Dimension(500,500));
     public Ta(int x, int y){
          super(x,y);
     public int print(Graphics g, PageFormat pf,int pi){
          if (pi >= 1) {
               return Printable.NO_SUCH_PAGE;
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(pf.getImageableX(),pf.getImageableY());
          Font f = new Font("Monospaced", Font.PLAIN,6);
          g2.setFont (f);
          g2.drawString(this.getText(),100,100);
          this.paint(g2);
          return Printable.PAGE_EXISTS;
2nd:
          b.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                    if(pj.printDialog()){
                         PageFormat pformat = pj.defaultPage();
                         pformat.setOrientation(PageFormat.PORTRAIT);
                         System.out.println(pj.defaultPage());
                         pj.setPrintable(ta,pj.pageDialog(pformat));
                         try{
                              pj.print();
                         catch(PrinterException p){

You got me wrong!My deepest regrets! :-)
Wait, somewhere I had seen some example of just this.
Ok... "found" it.
(As you shall see, the code is actually decompiled -by some demo application not commercial, mind you- so to find this useful you need to try to understand what all this variables are used for)
class NotepadPrinter implements Printable {
  public int print(Graphics g, PageFormat pageformat, int i) {
    Graphics2D graphics2d = (Graphics2D)g;
    try {
      return paintText(graphics2d, pageformat, i);
    } catch(Exception exception) {
      exception.printStackTrace();
    return 1;
  int paintText(Graphics2D graphics2d, PageFormat pageformat, int i) throws Exception {
    int j = (int)pageformat.getImageableHeight();
    int k = (int)pageformat.getHeight();
    graphics2d.translate(pageformat.getImageableX(), pageformat.getImageableY());
    graphics2d.setFont(getEditor().getGraphics().getFont());
    graphics2d.setColor(Color.black);
    String s = null;
    try {
      s = getEditor().getText(0, getEditor().getDocument().getLength());
    } catch(BadLocationException badlocationexception) {
      throw new Exception(badlocationexception.getMessage());
    java.awt.font.FontRenderContext fontrendercontext = graphics2d.getFontRenderContext();
    java.awt.geom.Rectangle2D rectangle2d = graphics2d.getFont().getMaxCharBounds(fontrendercontext);
    double d = rectangle2d.getWidth();
    double d1 = rectangle2d.getHeight() + 2D;
    double d2 = pageformat.getImageableWidth();
    int l = (int)(d2 / d);
    String as[] = getLines(s);
    int i1 = as.length;
    double d3 = d1 * (double)i1;
    int j1 = (int)((double)j / d1);
    int k1 = i1 / j1 + 1;
    int l1 = j1 * i;
    int i2 = getNumLinesForPage(as, i, j1);
    int j2 = (l1 + i2) - 1;
    if(l1 >= as.length)
      return 1;
    String as1[] = new String[i2];
    System.arraycopy(as, l1, as1, 0, i2);
    float f = 10F;
    LineMetrics linemetrics = graphics2d.getFont().getLineMetrics("A", fontrendercontext);
    double d4 = (double)linemetrics.getHeight() + 2D;
    for(int k2 = 0; k2 < as1.length; k2++) {
      graphics2d.drawString(as1[k2], 10F, f);
      f = (float)((double)f + d4);
    return 0;
  String[] getLines(String s) {
    StringTokenizer stringtokenizer = new StringTokenizer(s, "\n");
    Vector vector = new Vector();
    while(stringtokenizer.hasMoreTokens())
      vector.add(stringtokenizer.nextToken()));
    return (String[])vector.toArray(new String[0]);
  int getNumLinesForPage(String as[], int i, int j) {
    if(as.length < (i + 1) * j) {
      int k = as.length - i * j;
      return k;
    } else {
      return j;
}

Similar Messages

  • Why is my page set up drop down different from your illustration in help for printing background

    ''duplicate - https://support.mozilla.com/en-US/questions/830795''
    The page set up drop down menu looks nothing like the illustration in help. It does not include a box to check for "print background. How do I print background

    first, does it sound like I set it up correctly from what I wrote?
    Yes, all sounds correct.
    Second, I heard that adding a b/g AX to the network will slow everything down to b/g speeds but I have also read that simply using B/G AX's to add speakers by joining the network will not slow down the N network....which is it?
    The b/g AX devices will not slow down the network unless they are actively streaming AirTunes. Even then, audio streaming does not require a great deal of bandwidth, so for the most part, the effect would be negligible. Don't worry about it.
    Is my network slowed down to b/g speeds because of my speaker set up or not?
    The speed on your network will depend on a number of factors..are you downloading something while copying something else? Are you simply browsing? How far is the computer from the closest wireless access point?
    You can check your current available bandwidth on your local network by doing the following:
    Hold down the option key on your Mac while you click on the fan shaped AirPort icon at the top of the screen. Look for the Transmit Rate number.
    "g" wireless = 54 Mbps
    What do you see?
    Oh, and by the way, I don't know if this matters, but while the time capsule serves as the main base station, it is in bridge mode because it is plugged into a 2wire gateway router.
    If the Time Capsule is in bridge mode, it cannot act as the main base station. If you want, you could think of it that way if you are using the wireless on the Time Capsule as your preferred network, but the Time Capsule is not the "main" router.
    Message was edited by: Bob Timmons

  • Help for printing PDF docs.

    Hi, I am trying to print a PDF doc, and a window appear is " Prop Res DLL not loaded "!!!
    I can print everything except PDF file
    Thanks for you help
    PS: What is the meaning of ERROR Prop .....etc
    Ce message a été modifié par: chomedey657

    Hi, I am trying to print a PDF doc, and a window appear is " Prop Res DLL not loaded "!!!
    I can print everything except PDF file
    Thanks for you help
    PS: What is the meaning of ERROR Prop .....etc
    Ce message a été modifié par: chomedey657

  • Need help for printing/exporting in the right format

    Hi,
    i'm layouting a magazine for my graduation class.  And I almost finished it, but I've got a problem with printing it like I want it to be printed. I use the newest Trial Version of Adobe InDesign. The format of the magazine is A4, but when I export it as PDF (printing is the same) two pages (each A5) are exported on one horizontal A4 page. I want to have each page on one A4. Can somebody help me and say what I have to do, to get it work in my way?
    I hope you can help me, and I'm sorry if this is a silly question, but InDesign is a very complicated Software
    Thanks

    Exporting to PDF shouldn't resize the page. Does the exported PDF look the way you want it to?
    Here's all you need to know to export the file:
    File > Adobe PDF Presets > (pick a format - if you're printing from a desktop printer High Quality Print is a good choice)
    It might give you a warning about Transparency Blend Space which you can change under Edit > Transparency Blend Space
    Make sure spreads is not checked.
    If the problem is happening from Acrobat, check all of the settings in your print dialogue.
    Good luck!

  • Need help for printer application status

    Hi,
    I am using jdeveloper11.1.1.2.0.Actually standalone java application,I want to know status of the printer,If there is no paper inside printer then message should be display no paper in the printer,
    if i did printout but after 2 second i want to cancel the print then message should be also display ...
    my code is below..
    public void invokePrintJob(ActionEvent actionEvent) {
    // Add event code here...
    PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null);
    Boolean printerFound = false;
    for (int i = 0; i < printers.length && !printerFound; i++) {
    if (printers.getName().equalsIgnoreCase(getSelectedPrinter())) {
    printerFound = true;
    PrintService printer = printers[i];
    UploadedFile file = getTheFile();
    String fileName = getTheFile().getFilename();
    // String file = getTheFile();
    //PrintJobAdapter pr = new PrintJobAdapter();
    InputStream input;
    try {
    input = new BufferedInputStream((file.getInputStream()));
    Doc doc = new SimpleDoc(input, DocFlavor.INPUT_STREAM.PNG, null);
    PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    attrs.add(new Copies(2));
    attrs.add(OrientationRequested.LANDSCAPE);
    JobName name = new JobName(fileName ,null);
    attrs.add(name);
    DocPrintJob job = printer.createPrintJob();
    PrintJobWatcher pjDone = new PrintJobWatcher(job);
    job.print(doc, attrs);
    pjDone.waitForDone();
    System.out.println("--------jobRunning-end----------");
    input.close();
    } catch (PrintException e) {
    System.out.println(e.getMessage());
    addFacesErrorMessage(e.getMessage());
    } catch (FileNotFoundException e) {
    System.out.println(e.getMessage());
    addFacesErrorMessage(e.getMessage());
    }catch (IOException ioe) {
    // TODO: Add catch code
    ioe.printStackTrace();
    public static class PrintJobWatcher {
    // true iff it is safe to close the print job's input stream
    boolean done = false;
    PrintJobWatcher(DocPrintJob job) {
    // Add a listener to the print job
    job.addPrintJobListener(new PrintJobAdapter() {
    public void printJobCanceled(PrintJobEvent pje) {
    System.out.println("-------printJobCanceled--------");
    allDone();
    public void printJobCompleted(PrintJobEvent pje) {
    System.out.println("------printJobCompleted---------");
    allDone();
    public void printJobFailed(PrintJobEvent pje) {
    System.out.println("----------printJobFailed-------");
    allDone();
    public void printJobNoMoreEvents(PrintJobEvent pje) {
    System.out.println("--------printJobNoMoreEvents---------");
    allDone();
    @Override
    public void printJobRequiresAttention(PrintJobEvent pje) {
    System.out.println("-----------printJobRequiresAttention----------");
    allDone();
    @Override
    public void printDataTransferCompleted(PrintJobEvent pje) {
    System.out.println("-------printDataTransferCompleted---------");
    allDone();
    void allDone() {
    // System.out.println("---------------");
    synchronized (PrintJobWatcher.this) {
    done = true;
    PrintJobWatcher.this.notify();
    public synchronized void waitForDone() {
    try {
    while (!done) {
    wait(1000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    Please help me..

    Help with what? What's the actual problem?
    As far the code looks horrible. This kind of logic belongs in a fitler rather than a backing bean. You use empty strings instead of nulls. You stores passwords plain and unhashed in DB. You compares the password in Java instead of in DB. You stores password in a cookie. Your query is unsafe for SQL injections. You're reloading the driver class everytime when you acquire the connection. You're leaking DB connections. The application will crash sooner or later when the DB run out of connections.
    Is that all what you need to know?

  • Help for printer set up on NW 3.12.

    Does any one can help to set up a printer on my NW 3.12 server??
    Thanks!
    Dan

    Duplicate post (netware.discontinued forum). Please do not post a query
    in more than one forum at once, thank you.
    Andrew C Taubman
    Novell Support Forums Volunteer SysOp
    http://support.novell.com/forums
    (Sorry, support is not provided via e-mail)
    Opinions expressed above are not
    necessarily those of Novell Inc.

  • ICC help for printing to my Canon IP5200 from Aperture

    Am trying to find some ICC color profiles for my Canon IP 5200r printer. Since my reinstallation of Aperture my Canon profiles for the IP 5200 have disappeared. I looked for them on my old printer profiles.  i did find some profiles that i had made mysef but no canon provided profiles.
    I have gone to the Canon website and look for ICC profiles on their site and cannot find any. Any suggestions on what ICC profile settings to use to print from aperture to my canon 5200r.  Any suggestions

    re-instaled canon driver and the canon ICC profiles showed up profiles in aperture

  • I need help for printing service in Java

    Hello :
    I need to print some file from java program .
    I did every thing , but when i run the program : it didn't return any printer as print service from the system, although I install 2 printers in my system.
    by the way : i use Windows XP

    I was in a rush this morning and forgot my crystal ball. Please post your code and remember to use the code tags.

  • Need quick help for printer that vanished

    My printer was giving me trouble (it wasn't printing when I asked it to); while monkeying around in the printer setup utility, I somehow managed to delete the printer (an Epson Stylus Color 740) from my system--so now my computer thinks I do not have a printer hooked up! How do I get that beautiful printer of mine back in the loop? Thanks!

    There should be an "Add Printer" button on the Printer Setup utility, click it and follow the prompts. There is also a menu item under "Printers" that brings up the same dialog

  • On my HP printer Officejet4620 I get an error message "waiting for printer to become available".  Help please?

    On my HP printer Officejet4620 I get an error message "waiting for printer to become available".  Help please?

    Restart the computer and restart the printer. If you continue to have the problem the follow the steps Apple outlines in Reset Printing System feature article.

  • Need Help Please - PSD InDesign (for print)?

    Hello Everyone,
    I'm a graphic designer for a company that has decided to run some print ads in a magazine. At the time, I only had Photoshop to create their advertisement with. Now they have purchased CS4, which will make my life easier in the future, however, for now I have the problem of creating my advertisement made with Photoshop and creating a print ready PDF.
    Here is my problem:
    - I created a PSD at 8.5" x 11" at 300ppi
    - I did not take in to account for the 0.125" bleeds and 1/8" trim
    - It needs to be SWOP compliant (I figured out I can export a PDF that adheres to SWOP)
    - Fonts should be Type 1 Postscript, no TTF (I'm using Helvetica and Arial, when I export the PDF, it says the embedded fonts are TTF)
    - I'm totally lost with regards for designing work for print!
    Here the specs they gave me, AFTER I created the design in Photoshop
    ====
    Full page, full bleed 8.0" 10-3/4" (**I created my PSD as a 8.5" x 11" - without regard to bleeds**)
    Include 1/8 bleed over all to ensure full page bleed
    and keep live copy 1/4 from trim and crop marks.
    CMYK, 4-color process printing only.
    Do not add bleed to partial page ads.
    All requirements are based on Specifications for Web Offset
    Publications (SWOP). Any deviation from these specifications may
    result in less-desirable printed results.
    We support PDF files generated by Adobe Acrobat using
    the X-1A Job Option Settings for Distiller. In order for
    prepress to generate printable PDF s, it is important that
    the native file is prepared accordingly.
    Preparing native files for printable PDF s:
    All images/scans must be in CMYK mode,
    300 dpi resolution
    Use Postscript (Type 1) fonts only. No True
    Type, Windows/PC or custom fonts accepted
    Embed all fonts
    Do not nest EPS files in other EPS files
    Four-color solids should not exceed SWOP
    density of 280%
    Provide two digital color proofs at 100% size, created
    from the supplied digital file, on a contract-quality,
    digital halftone proofing system in accordance with
    SWOP web coated standards (AGFAPressmatch,
    Kodak Approval, DuPont Waterproof, etc.). Laser or
    inkjet proofs are not considered accurate in color and
    are supplied for content confirmation only.
    If supplied, the publisher is not responsible for color variances
    between the digital file and final color reproduction.
    NOTE: If proofs are not supplied, make-goods due to
    reproduction quality will not be honored.
    ====
    I've never done print work before, as I'm mainly a graphic designer for the web.
    Any help on this matter would be greatly appreciated! Unfortunately for me, they bought the advertisement space with the magazine for the running of the next issue before speaking with me. So I'm under extreme pressure to get this underway. I'll be most grateful for any help or guidance, Thanks guys!
    - D

    You can Place a PSD in Indesign, but unless the bleed is a single color,
    it's going to be easier to add bleed in Photoshop. Bleed is whatever
    gets cut off when they trim the paper. Trim is close, but not exact, so
    whatever picture or color goes to the edge of the paper must extend
    beyond the edge to avoid trim including some white when the trim is not
    quite perfect. If it's a picture that goes to the edge, you need to
    figure out a way to extend the picture beyond the edge. If it's white
    that goes to the edge, then you don't need bleed. If it's a non-tone
    color field (a single color) then you could Place the PSD in Indesign
    and add bleed color behind it and extending beyond the edge of the page.
    The magazine should not concern themselves with TT or T1 fonts, either
    one should work. That said, Helvetica and Arial are very close. If your
    Helvetica is Type 1, just use Helvetica for the whole thing. If you
    embed it in the PDF, it should show there as a Type 1 subset.
    Kenneth Benson
    Pegasus Type, Inc.
    www.pegtype.com

  • When saving a document as a PDF for printing, I lose pages, clip art, and my orginal format. Help!

    I have created some forms for our congregation to fill in with answers on adobe forms central. When I go to turn it into a PDF for printing for a hard copy, (not all our members have internet) when i save it to a PDF, it doesn't save all the pages and formats it differently then show on the screen i programmed it onto. How do I fix this issue?

    Hi;
    In the "Feature Tutorials/Help" linked from the top of the main page of the Forums: Feature Tutorials / Help
    There is a Tutorial on "Creating and distributing fillable PDF Forms": Tutorial: Creating and distributing fillable PDF forms
    The main thing to look at is the "View" setting and for PDF set it to "Page View", the page breaks you define in Page View will be used in the PDF, there are also "implicit" page breaks added automatically based on the page size.
    For the issue with clip art see this FAQ: Image does not show up in PDF 
    Thanks,
    Josh

  • Saving Illustrator CS4 file to PDF for printing. NO FORUMS CAN HELP

    I have put threads on the PDF forum, they told me to put it on Illustrator forum and still know one has an answer, Tried to contact Adobe about this and just got a run around. Can anyone please help?
    My problem results from when I save my file from Adobe Illustrator to a PDF for printing. After saving from Illustrator to a PDF and proofing it on screen all my gradients and other elements are where I need them to be on the page. But when I upload them to my printing company template all the gradients and so on are not even close to be in the right spot. How can I solve this problem, Is there a new setting in CS4 I need to know? Because I never had this problem with Illustrator CS3.

    Hi Reggie,
    I'm far from an Illustrator expert, but let's see if we can gather som more information form you that might help me, or someone else, figure out what's going wrong. Can you post a screnn capture of the arwork in Illustrator so I can see what the gradients are and how they're positioned? Use the little camera Icon thing in the toolbar above the message editing space on the web page.
    Next, tell us about the printer's template. What application is it made in? What version?
    What version of Illustrator and what OS are you using to create your art?
    Is it only the gradients that are in the wrong place? Maybe a screen shot of that would help too.

  • Need help to write code for 'Print" button......!

    Hi all,
    I am working in oracle forms 6i.I am creating forms for ordering product/quantity(Entering quantity/product details). In my form i have "Print button" to print the quantity details which is in multi-record block(database item).Please help me of how to write code for print button. If u had any source code please post it.
    Please help asap......!
    Thanks
    regards,
    jame

    You haven't got an answer or a reply because this question is asked so many times.
    Why don't you search the forum to find them?

  • I can't seems to print using my macbook air with hp series printers. When I plug the printer via usb to my system, the printer was recognized and installed. But when i send a doc for printing, it doesn't print all . Any help?

    i can't seems to print using my macbook air with hp series printers. When I plug the printer via usb to my system, the printer was recognized and installed. But when i send a doc for printing, it doesn't print all . Any help?

    Greetings,
    Here's a direct link to the drivers you need, they should work perfectly for your situation.

Maybe you are looking for