Very strange spacing when printing a JTextArea

I am trying to print text from a JTextArea and am having a very hard time at it. I am using a print utility which takes the component itself to be printed.
For instance:
If my JTextArea contains the text:
"Item: Large Caffe Mocha"
The printer will spit out something like:
"Item: Lar ge Caf f e Mocha"
Does anyone have any idea what is happening here?
Code is as follows:
public class PrintUtilities implements Printable {
  private Component componentToBePrinted;
  private boolean interactive;
  public static void printComponent(Component c, boolean interactive) {
    new PrintUtilities(c, interactive).print();
  public PrintUtilities(Component componentToBePrinted, boolean dialog) {
    this.componentToBePrinted = componentToBePrinted;
    interactive = dialog;
  public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    if (printJob.printDialog())
      try {
        System.out.println("Calling PrintJob.print()");
        printJob.print();
        System.out.println("End PrintJob.print()");
      catch (PrinterException pe) {
        System.out.println("Error printing: " + pe);
  public int print(Graphics g, PageFormat pf, int pageIndex) {
    int response = NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = componentToBePrinted.getSize(); //get size of document
    double panelWidth = d.width; //width in pixels
    double panelHeight = d.height; //height in pixels
    double pageHeight = pf.getImageableHeight(); //height of printer page
    double pageWidth = pf.getImageableWidth(); //width of printer page
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
    //  make sure not print empty pages
    if (pageIndex >= totalNumPages) {
      response = NO_SUCH_PAGE;
    else {
      //  shift Graphic to line up with beginning of print-imageable region
      g2.translate(pf.getImageableX(), pf.getImageableY());
      //  shift Graphic to line up with beginning of next page to print
      g2.translate(0f, -pageIndex * pageHeight);
      //  scale the page so the width fits...
      g2.scale(scale, scale);
      componentToBePrinted.paint(g2); //repaint the page for printing
      response = Printable.PAGE_EXISTS;
    return response;
}I am calling it as follows:
JTextArea area = new JTextArea("Large Caffe Mocha");
area.setRows(20);
area.setColumns(75);
area.setLineWrap(true);
JScrollPane pane = new JScrollPane(area);
printReceipt(area);
public void printReceipt(Component componentToBePrinted)
        PrintUtilities.printComponent(componentToBePrinted); 
}Thanks for any assistance with this problem. It is elluding me..

public static void printComponent(Component c, boolean interactive) {
new PrintUtilities(c, interactive).print();
printReceipt(area);
public void printReceipt(Component componentToBePrinted)
PrintUtilities.printComponent(componentToBePrinted); 
}I'm sure that this is not causing the issue and am also surprised that the compiler didn't complain, but your call to PrintUtilites.printComponent() doesn't sync up with the function you are calling. You are sending only one parameter (componentToBePrinted) and the printComponent() function is expecting two parameters: the component to be printed and a boolean value. In the code that you posted, you only had the one printComponent() function listed, with no alternative function that only accepts the component to be printed.
Having pointed this out, I'm not sure as to what is causing the issue, except that it may have something to do with your code:
//  scale the page so the width fits...
g2.scale(scale, scale);Maybe it's not really a spacing issue so much as a scaling issue. I know that on some systems, when you scale the graphics to print that are simple text, some letters will come out further apart and some will be squeezed together. I would suggest that you try commenting out your scaling code and let it print at the scale that it wants, just to see what happens.
Cheers,
Sean Carrick
PekinSOFT Systems
Edited by: PekinSOFT.Systems on Apr 16, 2009 8:27 PM

Similar Messages

  • Strange font when printing pdf with Reader X

    Hello,
    Who can help? I recently upgraded from Adobe Acrobat Reader 9 to Adobe Reader X. Since then, a strange problem occurs. When printing a pdf files to a printer, the font is changed. When viewing the file on the screen and printing them with version 9, everything is OK. The Arial font appears as it should. But when printing, a very ugly font type appears. The pdf files I use contain only a 'standard' Arial and Myriad Web font.This problem is very annoying.
    Can somebody help? I use version 10.0.1

    If you go the attached web page:
    http://www.adobe.com/support/reader/
    (http://www.adobe.com/support/reader/) ,  you
    will see "download an older version" underneath
    the Download Adobe reader.
    If you click in this link (download an older version), you
    can pick from version 8 and 9.
    Since erasing version 10 and downloading version 9.4,
    my problem has gone away completely.
    As with you, I consider this a major problem. It certainly added
    a lot of grief to my life when I could not trust my printer
    output at all.
    Hope this helps.
    Marsha

  • Character spacing when print

    Hi,
    How can I set the character spacing when I printing?
    eg. 10 CPI or 12 CPI etc. /CPI=Character Per Inch/
    thx.

    Hi,
    How can I set the character spacing when I printing?
    eg. 10 CPI or 12 CPI etc. /CPI=Character Per Inch/
    thx.Printing on what? Console or a UI component?

  • Very strange sound when using VoiceOver

    Hi I am using my apple tv with VoiceOver when I am whatcing one of my movies that whas both
    from iTunes Store and I puch the upp bottom on my remote 2 times to get the more info about
    the movie I get a very strange sound don't know how to desgribe the sound it dose only come up
    when the info aout the movie is up or any popup like window or is my hearing to good for my.

    And now the stranger things here... I didn't do much change to both the remote bean side and the client side, what I did is most like change it to something, and tried with failure, and change back.
    But today 's morning, when I just change everything back to suppose to be, and it can find the homebean:
    [2008-11-14 11:21:18,436] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) Looking up RepairEJB with JNDIName: RepairGatewayEJB_slsb
    [2008-11-14 11:21:18,531] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) h is not null!!
    [2008-11-14 11:21:18,532] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) got h: weblogic.rmi.internal.BasicRemoteRef@121 - hostID: '-891706141070674357S:113.128.134.59:[40010,40010,-1,-1,-1,-1,-1]:VPFSCTech:AdminServer', oid: '289'
    [2008-11-14 11:21:18,533] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) After ctx.lookup();
    [2008-11-14 11:21:18,535] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) homeBean is weblogic.rmi.internal.BasicRemoteRef@121 - hostID: '-891706141070674357S:113.128.134.59:[40010,40010,-1,-1,-1,-1,-1]:VPFSCTech:AdminServer', oid: '289'
    [2008-11-14 11:21:18,537] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) After home bean;
    [2008-11-14 11:21:18,589] [ INFO] [Thread-85] - Waiting for a request ...
    but unfortunately again it just stopped at
    remoteBean = homeBean.create();
    with no errors and exceptions...
    Does any experienced friends ever have this problem before?

  • Very strange crash when displaying pdf tumbnails in iBooks 1.5

    Hi,
    Recently, I have experienced a very strange behavior in iBooks. The app opened normally and then, some seconds later, dispaly getts blak and the app closes abruptly.
    I have traced back this behavior: It occurs just when the cover tumbnail of some pdf books is displayed in any iBooks' library view (both in bookshelf view and in Title view)
    I removed the troubesome pdf, but found that some others ( wich worked fine fron a lot of time ago) produce just the same behavior.
    When (using the painfully method of trial, and l, and trial again! And again,... )  i finally deleted all the crash - related pdf's, iBooks worked fine again.
    The most intriging features related this behavior are: 1- It is related only with tumbnails. All the pdf are normally vieved using some other ipad psdf viever (such as Kdan Pdf Reader or Adobe Reader for ipad) 2- If yoy remove the cover as pdf first page ( even if you move such cover and put it as the second page, using software like pdf sam) the pdf works fine in iBooks.
    I suppose this is a (annoying) bug, but,is there any suggestion? Is there any way to disable The tumbnail feature in iBooks?
    Best regards

    Somehow this bug came up on my radar yesterday later in the day: the first two comments indicate different plugins, and the third refers to the Acrobat plugin:
    <blockquote>This seems to happen if Adobe Reader is used for displaying PDF documents (pdfjs.disabled set to true and Preferences > Applications > PDF to "Adobe Reader (in Firefox)").<br><br>Opening two tabs displaying PDFs and closing one crashes the other one.<br><br>Was able to reproduce with Firefox 36.0.1 and Adobe Reader plugin "Adobe Acrobat 11.0.10.32". When I tried to reproduce it later again in the same profile (or on Nightly and Beta), the tab didn't crash.</blockquote>
    https://bugzilla.mozilla.org/show_bug.cgi?id=1113190
    Sounds like your issue, but it's puzzling that they got a tab to crash and in your case only plugin-container.exe crashed.

  • Very strange behavior when on charge.

    When on charge at night my 5s opens and plays random Utube videos from time to time. Last night as we were laying in bed just about to go to sleep we heard my phone clicking, it turns out it wrote a short text message to someone on my contact list, its nothing to do with siri as we were both silent and about to go to sleep when it happened. Has anyone else heard of this.

    I had this very same problem when i did the switch. The thing was that there where two tools providing this functionality. The gnome power tool thing and some acpi feature started with systemd.
    Try disabling one of them.

  • Problem with dashed line spacing when printing to pdf

    Hi all,
    this may be a problem with my pdf program (I use bluebeam), but maybe someone will have an idea how to fix it whether in indesign or bluebeam.
    so I made a dashed line using the stroke command in indesign. I need to have the spacing set to 3pt dash and 2pt space. I also need to keep the lineweight to 0.5...this all works fine and appears correctly in indesign when I preview
    the problem is that some of the dashed lines, but not all of them, change size and spacing in the pdf when I view it. it seems to change when I zoom in and out as well. I thought maybe this was just some odd feature with bluebeam and it would still print to the correct size, but it does not, it prints the lines as different sizes. does anyone have an idea why this happens and how to fix? ive viewed and printed from adobe reader and it seems to be okay there but this file will be accessed by multiple other people and they may not be opening and printing in adobe reader..
    thanks guys

    When you export a PDF you will notice that you are exporting to Adobe PDF. Using any reader beyond Acrobat Pro or Reader is a crapshoot.
    For issues with Bluebeam I suggest you contact the developer.

  • Strange characters when printing

    I don't know what happen but when i select printing reader open a Windows with characters very very big and buttons are disapeared and when i click on preferences i get this image.I uninstalled and installed acrobat reader 11 (last versión) and vga drivers, without solution. Any idea?
    Hello.

    I'm using Windows 7 profesional 64 bits. I don't install any fonts. All fonts i have are default (except if something has installed another fonts but i think that not).
    This only happen in acrobat reader.

  • Strange issue when printing PDF's

    This problem started the other day. Whenever I scan to a pdf file or Save as from Illustrator the PDF looks fine (using the High Quality Setting) but prints out like a rastered high contrast jpeg image (with artifacting around all the edges of text and images). I thought this was a Distiller issue and checked all my settings. No Luck.
    This morning I opened and tried to print a clients file and same thing happened. The problem occurs to both black & White laser printer as well as Epson R2400
    I am using CS3  Updated to version 8.1.4 this morning on a windows vista machine.I would reinstall acrobat but when I had to do that a previous time, Vista and Acrobat would not play nice and I could never get Acrobat to install completely until I reformatted my whole drive and started from scratch. I do not have the time or want to try that again.
    Could the preference file be bad? And where is that located?
    Thanks,

    This is not a scanning resolution factor and I have been scanning this way for years. These scans are not photos but documents. This problem just started.  And as I said before, the problem also occurs when doing a save as from Illustrator, as well as supplied files from clients, so the scanning process has nothing to do with it. I just can't get them to print right.

  • Very Strange occurance when page with effect viewed in IE 7

    I applied the spry (Fade/Appear) effect to a container.
    The container contains text and images. When I test the page,
    I noticed the images has strange white marks or scratches on them.
    Has anyone noticed this? This only happens in IE 7. Not Firefox.
    I also noticed a gap between the tabs at the bottom of the
    page and the container when the effect (Fade/Appear) is applied.
    There also appeared to be a latency when I click on the tabs
    and when the effects happens.
    Like you click on the tabs and the effects occurs after about
    two seconds.
    Can you adjust the time it takes for the effects to fire up
    when you click on a tab?
    Just wondering if anyone has experience any of these
    problems.
    Patrick

    quote:
    Originally posted by:
    Newsgroup User
    Webethics wrote:
    > I applied the spry (Fade/Appear) effect to a container.
    > The container contains text and images. When I test the
    page, I noticed the
    > images has strange white marks or scratches on them. Has
    anyone noticed this?
    > This only happens in IE 7. Not Firefox.
    > I also noticed a gap between the tabs at the bottom of
    the page and the
    > container when the effect (Fade/Appear) is applied.
    >
    > There also appeared to be a latency when I click on the
    tabs and when the
    > effects happens.
    > Like you click on the tabs and the effects occurs after
    about two seconds.
    >
    > Can you adjust the time it takes for the effects to fire
    up when you click on
    > a tab?
    You should post a link to your page so that others can see
    what is going on, and potentially offer some suggestions.
    I've not seen any "delay" options for starting effects. It
    may be that something is interfering with start of the effect.
    Danilo Celic
    |
    http://blog.extensioneering.com/
    | WebAssist Extensioneer
    | Adobe Community Expert
    This is the URL
    http://www.patrickjudson.com/weddingIndex.php,
    The effect is on the first tab, not the others. you can click any
    other tab and then click the first tab to see the effect. What I
    mentioned above only happens in IE 7.
    thanks again - Patrick

  • Strange behavior when printing a PO in SRM

    Hi,
         We just done a copy of environment and have upgraded the kernel. When we try to print a PO (from the output tab in the PO) we are getting the error Device Window default printer does not exist. Moreover when i went in debug i found that the error appears when the conversion exist SPDEV is called. There a select is carried out in table TSP03L with the value stored in the printer area. What is weird is that the entry exist in the table but the value stored on the screen seem to hold a special characters that makes its unable to find the correct entry.
    Have you ever encounter this issue. Is it possible to define different character set for the back-end and the srm web pages?
    Thank you for your help.

    I found a solution.   Rename the Text layer by adding a space before or after the numerals.  Now the duplicates are named as the written text with a suffix  increased by 1 for each additional duplicated layer.

  • Very strange issue when displaying the Account PDF Factsheet.

    We have a very odd situation.
    We have one users (user1) who has the same business role as everyone else in the office. They can enter the UI (CRM 7), display an account and then click on the PDF Factsheet option. It seems to process and then simple says 'Done', but there's no PDF document displayed. At first I thought it was an Adobe issue, but, if someone in the office (user2) logs into SAP on user1's  PC (in the same Windows session), they can perform the same process in the UI and the PDF is displayed, so it can't be a PC related issue, and must somehow be related to user1's SAP profile or role in some way.
    Comparing User1 and User2's roles displays no differences, and their SU01 entries are also the same.
    Can anyone come up any recommendations as to what it could be?.
    I've more or less exhausted all my options.
    Jason

    I think we have discoverd what is causing the problem.
    In CRM 7, when you view an Account (BP) the first assignment block to be show is the account details block. If you have this block collapsed (not expanded) or not on the screen at all then PDF fact sheet does not work. If I then expand the Account details block and review the PDF Fact Sheet, it then displays perfectly.
    I guess there must be some dependancy of the PDF Fact sheet on the Account details block. I placed a breakpoint (normal and external) in the method of the class CL_UIU_PRN_ACCOUNT, but this code never gets called when the Account details block is collapsed. I'll have to find out what code is executed before this class/method is called.
    Jason

  • Very strange issue when using initial context to lookup for beans...

    hi, friends,
    I am currently try to call a bean from a remote ejbclient.
    I set the initialcontext like this with the url suppose to be:
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, url);
    ctx = new InitialContext(p);
    and look up home like this with the Name suppose to be:
    Object h = null;
    h = ctx.lookup(Name);
    but the strange thing is, the programme just stops when it is doing ctx.lookup(Name); However I try to log it, but it is just stopping there, without throwing any exceptions and errors.
    But, when I gave it a wrong name to like at, it could go through ctx.lookup(Name), and throw some exceptions like "unnable to look up beans.." which I put in the catch part...
    I try to echo the "ctx", and it is not null. and I try to echo "h", but it just stop before the "h" getting anything...
    the ejbclient is compile with jdk 1.4, because it is on a server with jdk 1.4, and deployed on weblogic 8.1. and the bean.java is compiled with jdk 1.5, and deployed on weblogic 10.
    Does anyone knows what is really going on here, when doing the lookup, what happened?
    How could I know whether there are the ejbs I need to call are existing in the pool?
    Thanks..
    Looking forward helps. such an problem has bothered me for a couple of days, and my boss is pushing me on this. but I haven't get any idea on it...:(

    And now the stranger things here... I didn't do much change to both the remote bean side and the client side, what I did is most like change it to something, and tried with failure, and change back.
    But today 's morning, when I just change everything back to suppose to be, and it can find the homebean:
    [2008-11-14 11:21:18,436] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) Looking up RepairEJB with JNDIName: RepairGatewayEJB_slsb
    [2008-11-14 11:21:18,531] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) h is not null!!
    [2008-11-14 11:21:18,532] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) got h: weblogic.rmi.internal.BasicRemoteRef@121 - hostID: '-891706141070674357S:113.128.134.59:[40010,40010,-1,-1,-1,-1,-1]:VPFSCTech:AdminServer', oid: '289'
    [2008-11-14 11:21:18,533] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) After ctx.lookup();
    [2008-11-14 11:21:18,535] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) homeBean is weblogic.rmi.internal.BasicRemoteRef@121 - hostID: '-891706141070674357S:113.128.134.59:[40010,40010,-1,-1,-1,-1,-1]:VPFSCTech:AdminServer', oid: '289'
    [2008-11-14 11:21:18,537] [ INFO] [Thread-85] - {} getRemoteBean(Unknown Source) After home bean;
    [2008-11-14 11:21:18,589] [ INFO] [Thread-85] - Waiting for a request ...
    but unfortunately again it just stopped at
    remoteBean = homeBean.create();
    with no errors and exceptions...
    Does any experienced friends ever have this problem before?

  • Strange colors when printing (lightroom & epson pro 3800)

    After buying a new computer I'm having printing problems in lightroom.
    Printing with other software (photoshop for example) works flawless.
    I've used new and old drivers for my printer: didn't change a thing
    I've looked at different printing profiles, custom or letting the printer handle it: hardly any improvement
    The problems appairs with lightroom 2.4 64bit installed on a windows vista 64bit version.
    The printer I'm using is a epson pro 3800. Normally i would say it's a driver problem.. (on my old computer (xp 32bit) it's works fine) but the problem only appairs in lightroom. And i used a few drivers. I must be missing a setting or something.
    Does anybody have an idea?
    You can look at the attachment to see the problem i'm having.
    Thanks in advance

    I am also suffering with the light room print module.
    My Eizo monitor is calibrated with a Gretag Macbeth i1Pro.
    My printer profiles are paper and ink specific.
    In CS3 my working color space is Adobe RGB(1998) and my prints are a perfect match to the monitor appearance on both an Epson Photo 2200 as well as an HP Pro B9180.
    I understand that there is no soft proofing option in LR 2, but is there any work around to change the working color space in LR to Adobe RGB(1998) and get a decent print without kicking the image over to CS3 first? Since both products are from Adobe, I don't understand why they should be working at cross purposes.
    I went to Photo Expo in NYC today, but unfortunately Adobe did not take their usual booth at the Javits Center so that I might address the question to an Adobe specialist.
    Thanks
    Jay

  • Please help, Very strange issue when generate different template

    Hello, Can someone help for below Strange Problem.
    1. The PDF template files are defined in BI Publisher Layout as a.pdf, b.pdf
    2. the parameters are defines in BI too
    4. logic as below, generated PDF based on a.pdf. generated PDF based on b.pdf,
    then merger a.pdf and b.pdf together.
    5. Codes for generated PDF as below
    this.reportDefinitionResp = bIPublisher.getReportDefinition(this.reportAbsolutePath, this.userID, this.password);
    this.reportRequest = new ReportRequest();
    this.reportRequest.parameterNameValues = this.reportDefinitionResp.reportParameterNameValues;
    this.reportResponse = bIPublisher.runReport(this.reportRequest, this.userID, this.password);
    6. the PDF generated by the a.pdf is correct, but generated by the b.pdf is not correct, instead it is same as a.pdf?
    so after merger, we get the duplicate pages.
    7. Not all templates has same issue, sometime we get this issue, how to fix it?

    Hi
    Click your HD to go to Finder,
    Go to Your User/Library/Caches,
    Drag com.apple.preferencepanes.cache to trash
    Restart your macbook.
    Good Luck.

Maybe you are looking for

  • Can I use MSVC 2013 to develop plug-in for InDesign CC 2014?

    The minimum requirement is MSVC 2012 SP4. I wonder if the latest version will work also. Thanks.

  • What's new in Adobe Presenter 8.0

    This question was posted in response to the following article: http://help.adobe.com/en_US/presenter/using/WS5f497c91827355fd-5f2f6997137bf36849a-8000.ht ml

  • BI Security issue

    Hi, We applied BI Security filters for two of the facts which are used in our report. Issue is report is erroring out , only one security filter is getting applied corresponding to one fact. Can anybody comment on why this is happening. fyi : Both fa

  • Zen Micro A/C power cord opti

    Hi All, My Micro recharges just fine when plugged into the USB of my computer with Creative software. However, it will not charge using USB on other computers. Also, I tried plugging in my Blackberry charger (output 5V,?0.7A)?to the USB port. The Mic

  • 6500 prints too small

    I have an All in One 6500 printer that I bought at Christmas time.  When printing anything online, (whether I highlight & print selection or print the whole webpage), the fonts and everything shrinks and is too small to read.  I have looked through t