Sending a JPanel to the printer...

All,
I wasn't sure if this was the appropriate forum for this, but I couldn't find one specific to printint to a printer.
I'm trying to send a JPanel to a printer.
I have the following routine which seems to more or less work, but exhibits a few problems. I've gotten most of the code off a website.
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);
          // scale to fill the page       
          double dw = pageFormat.getImageableWidth();
          double dh = pageFormat.getImageableHeight();
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          double xScale = dw / screenSize.width;
          double yScale = dh / screenSize.height;
          double scale = Math.min(xScale,yScale);
          // center the chart on the page
          double tx = 0.0;
          double ty = 0.0;
          if (xScale > scale)
              tx = 0.5*(xScale-scale)*screenSize.width;
          else
              ty = 0.5*(yScale-scale)*screenSize.height;
          g2d.translate(tx, ty);
          g2d.scale(scale, scale);
          componentToBePrinted.paint(g2d);
          enableDoubleBuffering(componentToBePrinted);
          return Printable.PAGE_EXISTS;
  /** The speed and quality of printing suffers dramatically if
   *  any of the containers have double buffering turned on.
   *  So this turns if off globally.
   *  @see enableDoubleBuffering
  public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
  /** Re-enables double buffering globally. */
  public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);
}Now I get things to print by calling the printComponent method and passing in my JPanel. No problem, the scaling and all works.
However, whether I scale things to fit the page, or remove that code, I get some strange behavior.
The JPanel has a few JLabels scattered about in a GridBagLayoutt, in three general columns.
However, I've noticed that some of the items in each column get truncated and have "..." tacked onto the end. But it doesn't do this to just the longest items, it also does it to shorter items, even if a longer one in the same column was NOT truncated in this manner.
So, what I'll have in one column is something like:
A long line that's been truncated...
a short line, no problem
a short line truncated...
longer than above, not truncated
On screen, it's normal. Printed out, those weird truncations occur.
Why is this happening? There's plenty of room, and each of the lines that are getting truncated could easily be 1-1/2 times their length without the danger of bumping into the next column.
Is there any way to for me to force it to print the entire line?
Thanks!

ADDENDUM: Another problem I'd like to solve is that, the JPanel is gray with black text. I'm fine with that onscreen, but when it prints out, it prints a gray rectangle for the panel, with black text on it. Is there any way I can have this not print out the background as well (ie: treat background as white and only print the text that's on the JPanel?)

Similar Messages

  • InDesign CC no longer packages fonts when I need to send a project to the printer

      Hey Adobe team: Long-time user from when Photoshop was but a sprout. I recently upgraded from Creative Suite 6 to Creative Cloud and have run into a troubling problem. InDesign CC no longer packages fonts when I need to send a project to the printer. This meant that I had to completely redo a project on deadline for a problem that I’ve never had before. How is this possibly helping your users? And is there a solution in the works or do I need to cancel Creative Cloud and go back to CS6?

    @OurPlace
    First of all, you are not addressing any Adobe team. These forums are primarily supported by volunteers who are not Adobe employees and don't officially represent Adobe Technical Support.
    That having been said ...
    There was nothing done specifically with InDesign 9 or 10 (the CC and CC 2014) versions of InDesign to change or disable packaging of fonts when packaging a document. It should be absolutely no different from InDesign 8 (the CS6 version).
    Troubleshooting hints:
    (1)     Make sure you check the Copy Fonts (Except CJK and TypeKit) option in the package dialog.
    (2)     Make sure that you are not using any CJK (Chinese, Japanese, and Korean) complex fonts that we specifically will never put into a package.
    (3)     TypeKit fonts won't package.
    (4)     Make sure that your file system permissions are such that InDesign can create all the necessary directories and subdirectories for the packaging operation.
    (5)     If on MacOS, exit InDesign and try forcing a clearing of your system font cache and then reboot.
    (6)     Exit InDesign and then find and delete all files on your system with filenames of the form AdobeFnt##.lst where ## is a two digit number; don't delete any other files that start with AdobeFnt. Then reboot and restart InDesign.
    (7)     Reset InDesign's preferences that may have become corrupted. For Windows, start InDesign, and then press Shift+Ctrl+Alt. Click Yes when asked if you want to delete preference files. For MacOS, while pressing Shift+Option+Command+Control, start InDesign. Click Yes when asked if you want to delete preference files.
    One of these should either address or resolve your problem. Again, we at Adobe are not aware of any generic issue with packing fonts with InDesign.
              - Dov

  • Trying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.

    rying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.
    Does anyone know how to fix this?

    What EXACT version of Photoshop CS4 are you running?  You should be on Photoshop CS4 v 11.0.2.
    Also run Apple's software update to see whether it offers you the latest Epson update:
    Printer Driver v9.33
    Epson Stylus Pro 3880, Drivers & Downloads - Technical Support - Epson America, Inc.
    MOST IMPORTANTLY:  have Photoshop re-create its own Preferences:
    To re-create the preferences files for Photoshop, start the application while holding down Ctrl+Alt+Shift (Windows) or Command+Option+Shift (Mac OS). Then, click Yes to the message, "Delete the Adobe Photoshop Settings file?"
    Note: If this process doesn't work for you while you're using a wireless (Bluetooth) keyboard, attach a wired keyboard and retry.
    Important: If you re-create the preferences by manually deleting the Adobe Photoshop CS6 Settings file, make sure that you only delete that file. If you delete the entire settings folder, you also delete any unsaved actions or presets.
    Reinstalling Photoshop does not remove the preferences file. Before reinstalling Photoshop, re-create your preferences.
    NEW Video! Julieanne Kost created a video that takes you through two ways of resetting your Photoshop preferences. The manual preference file removal method is between 0:00 - 5:05. The keyboard shortcut method is between 5:05 - 8:18. The video is located here:
    How to Reset Photoshop CS6’s Preferences File | The Complete Picture with Julieanne Kost | Adobe TV
    Mac OS
    Important: Apple made the user library folder hidden by default with the release of Mac OS X 10.7. If  you require access to files in the hidden library folder to perform Adobe-related troubleshooting, see How to access hidden user library files.

  • How can I get Acrobat Reader X to send my pdf to the printer?

    My pdf just looks at me while I push all of the buttons, file menus and keyboard shortcuts associated with printing and it does nothing. No dialog box, no nothing. All three of my printers work and i've tried them all. It just doesn't do anything. Any suggestions? I really need help here.

    From: Pat Willener [email protected]
    Sent: Monday, July 30, 2012 9:16 PM
    To: vinniereed
    Subject: How can I get Acrobat Reader X to send my pdf to the printer?
    Windows 7; Acrobat Reader 10.0; local and online.
    Thanks,
    Vinnie
    Re: How can I get Acrobat Reader X to send my pdf to the printer?
    created by Pat Willener <http://forums.adobe.com/people/pwillener>  in Adobe Reader - View the full discussion <http://forums.adobe.com/message/4588698#4588698

  • How to turn off printing message box that appears every time I send a document to the printer?

    How to turn off printing message box that appears every time I send a document to the printer?  Appears bottom right corner of screen above task bar.  Printer is HP c309a All-in-One PhotoSmart printer.

    I have an Iphone 4s, and every time I receive a call and i dont answer it, the cell shows a black screen with many things to do and automatic messages to send, like "call back, save, remind, call now, call later, etc". If I don´t close it as soon as i receive the call, then the cell gets frozen in that screen and i have to restart it. Sory for my english, i´m from argentina! thaks for your help !!!

  • Urgent, To send a report to the printer

    hello
    I have develops an application with devlopper suite 9.0.4, and when I want to print the report without posting it on the screen, I use web.show.document
    with destype=printer
    desname=Imprimante
    when I use the local print server, everything works well
    but when I puts the report on the server (Linux+IAS 904), and I use the printing server, it posts me an error, “Left with error code (1)”
    help me PLEASE

    Hello,
    On UNIX systems, Reports wil use the script $ORACLE_HOME/bin/rwlpr.sh to send the output to the printer.
    It is possible to trace the execution of rwlpr.sh :
    Note.268295.1 How To Debug REP-50157 Error while sending file to printer <...>. Exit with error code <...>:
    Regards

  • Send a file to the printer!

    Hello,
    is it possible to send a file, that is generated with the
    printer-driver, to a network-printer? This should be done with LabVIEW
    6i
    Jens

    [email protected] (VI Guy) wrote in <5065000000050000007CAB0000-1031838699000
    @exchange.ni.com>:
    >Yes and no.
    >
    >The printer has to be of the type that allows this (I don't know the
    >exact requirement but some printers allow it and others don't).
    >
    >Set up your computer so the network printer is "mapped" to printer
    >port like "LPT1" or "LPT2" (If I recall this requires you to answer
    >yes to the "Do you print from MS-DOS applications?" during the "Add a
    >Printer" wizard).
    >
    >Then, you will need to use the "Shell Exec.vi" and do a "COPY /B
    >Filename.bin LPT1", given that "Filename.bin" is the file you created
    >with the print driver and "LPT1" is the port you mapped your printer
    >to.
    >
    Alternatively if it's just a plain old text printer, you can use the serial
    vi's
    to send the text directly to a line printer using COM10. Note that you
    will have to include a line in your labview.ini file (and in the ini file
    with your built application) that allows you to access com10. The line is
    something like:
    "serialDevices=com1;com2;com3"
    but a search on using the line printer on the NI website will reveal the
    correct key and entry.
    Alexander C. Le Dain, PhD
    ICON Technologies Pty Ltd
    http://www.icon-tech.com.au
    * The LabVIEW FAQ http://www.icon-tech.com.au/thelabviewfaq.html *

  • Running Yosemite, printing to xerox c75 digital press. InDesign will send a file to the printer, then crashes every time. I know there was a patch for this problem. Where do I find it?

    Whenever I send a file to my Xerox C75 from my Mac (Yosemite), the file goes to the printer okay, then InDesign crashes.
    I think there is a patch specifically for this issue. Where do I find it?

    Yes, I have Fiery Hot Folders Console.  That is certainly an alternative that should work as I can then avoid having to choose Fiery Features from the print dialog box in order to choose the paper tray and other features I need.
    I am about to try a clean install of OS 10.9.3, and I am not the least bit happy about it.  Adobe CC is my main set of go-to applications for my work, and those are the only applications that give me ANY problems with printing.  I have forked out real money on different versions since I started using Adobe in the late 1990's, and my troubles seem to increase with every new release.

  • Why can't i send my pictures from the printer to the computer

    I put my memory stick from my camera into the slot on my HP officejet 6500A plus, and it does not give me an option to send it to my computer for my files.  It only gives me View and Print,  Create and Reprint... why can't I send the pictures from that memory stick to my computer from the printer?  Thanks

    I put my memory stick from my camera into the slot on my HP officejet 6500A plus, and it does not give me an option to send it to my computer for my files
    What did you mean by that ?
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Often when I send a job to the printer, it either sits idle in the queue, or says **bleep** is printing.

    The jobs queue up but won't print. Deleting does not work nor does "restart.". However, when I restart my computer, when it reboots, the print jobs then print. Not very efficient. Printing from my iPad works fine.

    Its okay, I just spent an hour searching for an OJ 6510 and could only find a photosmart 6510... lol
    Check out this article: http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02205477&cc=us&dlc=en&lang=en&lc=en&product=408...
    There are a lot of steps to follow but it is very important that all of them are followed to resolve this problem.
    Hope this helps!
    Help the community by marking this post as a solution if it solved your issue!.
    If my post helped you in any way, please click the blue KUDOS star under my name! It would mean a great deal.

  • When we send a job to the printer (C7280) it will print that one job multiple times even though we

    When we print a job to the C7280 All in one it prints multiple copies when sent from our Mac Book Pro.

    You can have a separate AppleID only for iMessage and keep using the other one for iTunes.
    Just change the AppleID used for iMessage in Settings > Messages > Receive At

  • How I can send a report directly to the printer "EPSON TMU 220" from form11

    Dear,
    I have a problem with Oracle Forms11g, I need send a report to the printer EPSON TMU-220 (Pos of sale printer) in the client machine.
    Please, help.
    Thanks
    JC

    Dear,
    The problem is:
    I need to send the report directly to printer. All other reports work fine with other printers in the network.
    But the EPSON TMU-220, (I changed the card connection from COM to USB, and nothing)
    Please, help me.
    JC

  • What's the printing difference in Acrobats 8 and 9 Pro?

    I have a PDF, actually I have seen quite a number, that when sent to one of our Canon printers--4080i or 2550--from Acrobat 8 Pro will not print. Nothing comes out. (Actually 1 the printer shows that it received one page--the document had more than one page--but it does not print that page out. We can set Print as Image in the advanced dialog and the document prints. The same document sent from Acrobat 9 Pro does print.
    Does Acrobat 9 have printing features that Acrobat 8 does not have? Will Acrobat 9 print the same document differently than Acrobat 8 will print it--Fonts, colors, resolution, etc.?
    If anyone is going to tell me to preflight the PDF, Thank You. If you do, please give me specifics as to what settings to use so that the PDF can be printed from any version of acrobat, 7 or higher, to any type of printer.

    No Answer yet.  This makes we wonder if anyone out there has had documents that will print in Acrobat pro 9, that will not print in acrobat pro 8. If so is there a reason? If all else is equal, XP, Printer Canon 4080i, Printer drivers, etc. And the only difference is Acrobat 8/9. Then it seems to me that there is some difference in the way the different version of Acrobat send PDF's to the printer. Am I correct?

  • Sending reports directly to a printer (commands) 10g Linux

    Hi,
    Quick question. I am trying to confirm what I need to pass to Oracle Reports Server in order to print directly to the printer (bypassing any Preview or PDF version of the report in Oracle 10g. I am using Linux. We just installed the printer on the server. I modified to the uiprint.txt file under the ORACLE_HOME/tk/admin to point to the new PPD that we copied for that printer to ORACLE_HOME/guicommon/tk/admin/PPD.
    Below is the report call I am making. I just want to verify that what I did was correct. I am currently receiving a FRM-41214: Unable to run Report. When I run the same report via the PDF option that displays in a separate browser window, it brings the same report up correctly.
    SET_REPORT_OBJECT_PROPERTY('GENERICREPORT', REPORT_FILENAME, LOWER(:MODULE.MODULE_NAME)||'.rep');
    SET_REPORT_OBJECT_PROPERTY('GENERICREPORT', REPORT_SERVER, 'rep_inpp37_gt');
    SET_REPORT_OBJECT_PROPERTY('GENERICREPORT', REPORT_OTHER, V_OTHER);
    -- V_OTHER is my parameters that I pass, such as PARAMFORM=NO, READONLY=yes, PAGESIZE, ORIENTATION, DELIMITER=NONE, and parameters which in this case there are none.
    SET_REPORT_OBJECT_PROPERTY('GENERICREPORT', REPORT_DESTYPE, PRINTER);
    SET_REPORT_OBJECT_PROPERTY('GENERICREPORT', REPORT_DESNAME, 'gt-ybs-p'); - this is my printer name
    V_REP := RUN_REPORT_OBJECT('GENERICREPORT');
    When it runs the V_REP line, that's when I get the FRM-41214 error. Just was wanting to verify if what I had passed for the printer commands is correct.
    Chris

    I forgot one important piece which is why I am asking the question. I am running the report within an Oracle 10g form. I pass all the parameters across to the Reports Server, as seen above. When I run via the PDF option, I just change the DesType to Cache and DesFormat =PDF. When I run with this, it works and displays the report in a new browser window.
    I just want to run the report with the exact same parameters but instead of generating a PDF, I want to run the report and send it directly to the printer without previewing it.
    Chris

  • Do I need and app to eprint or can I just print from my e-mail to the printer?cc=us

    I can not eprint to my printer and the services are turned on. Everytime I try to send an email to the printer to print it come back with a failure notice. Can someone please help?

    Make sure you are only entering one email address in the "TO" and nothing in the CC or BCC 
    If you go to your ePrint Center and enable the security feature, you can add your email address.
    Next time you send a job to print it will send you back more detailed information as to why it is not printing.
    Although I am not affiliated with HP, please give Kudos if I've answered your question

Maybe you are looking for

  • " In the iPhone is activated the number of free accounts. "

    Hey! Who can help? "You can not check. In the iPhone is activated the number of free accounts. " What can I do in order to use a program (my friends) to which the breakaway iCloud??

  • Premiere 8.0.1 patch now available by direct download

    http://www.adobe.com/support/downloads/thankyou.jsp?ftpID=4653&fileID=4342 Cheers, Neale Insanity is hereditary, you get it from your children

  • Bill of Material Explode

    Hi Experts, If I want to calculate the Component scrap in percent at all the levels of BOM What is the way to proceed for it. Thanks in Advance. Regards, IFF

  • Opening jpegs into camera raw

    I have CS3 Windows and have been reading Kelby's book 7-Point System where he opens jpegs into camera raw. However, the explanation is poorly written for someone who has never done that. Can someone explain? Thanks. Don

  • Package, unit and time dimensions

    Hi. I understand that a star schema can have max of 16 dimensions out of which 13 can be defined. what are other three package, unit and time dimensions?are they used in all cubes? are they defined by SAP system itself? please help rajesh