Printing JPanel results with a blank page

I have been trying to print a JPanel with out any luck, I've read the various examples, http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html and http://java.sun.com/developer/technicalArticles/Printing/SwingPrinting/
I can get the print dialog no problem and the printer starts up and prints, but theres nothing on the sheet.
Am I missing something entirely?
main screen
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {
             Memo m= new Memo(); // the JPanel to print
             m.componentToPrint(m);
             PrinterJob printJob = PrinterJob.getPrinterJob();
             printJob.setPrintable(m);
             if (printJob.printDialog())
             try
                printJob.print();
             catch(PrinterException ex)
                System.out.println("Error printing: " + ex.getMessage());
}The JPanel to print
package nonconforming;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import javax.swing.RepaintManager;
public class Memo extends javax.swing.JPanel implements Printable{
    /** Creates new form Memo */
    public Memo() {
        initComponents();
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/nonconforming/bgmlogo.png"))); // NOI18N
        jLabel2.setFont(new java.awt.Font("Arial", 1, 18));
        jLabel2.setText("BGM Fastener Co., Inc.");
        jLabel3.setFont(new java.awt.Font("Arial", 0, 11));
        jLabel3.setText("759 Old Willow Ave. Honesdale, PA 18431");
        jLabel4.setFont(new java.awt.Font("Arial", 0, 11));
        jLabel4.setText("Phone: 800-233-4270/570-253-5046/FAX 570-253-2469");
        jLabel5.setFont(new java.awt.Font("Arial", 0, 11));
        jLabel5.setText("Email: [email protected] Website: http://bgmfastener.com");
        jLabel6.setFont(new java.awt.Font("Dialog", 2, 36));
        jLabel6.setText("MEMO");
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addContainerGap(103, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addContainerGap(32, Short.MAX_VALUE))
                                .addComponent(jLabel5))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel6))))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap(62, Short.MAX_VALUE))
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration                  
    private Component printComponent;
public void componentToPrint(Component c)
    printComponent=c;
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException{
        if (pageIndex > 0)
          return(NO_SUCH_PAGE);
        else
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          // Turn off double buffering
          disableDoubleBuffering(printComponent);
          printComponent.paint(g2d);
          // Turn double buffering back on
          enableDoubleBuffering(printComponent);
          return(PAGE_EXISTS);
public static void disableDoubleBuffering(Component c)
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
public static void enableDoubleBuffering(Component c)
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);
}Thank you for any help

Search google for "StandardPrint.java" and you will find my StandardPrint class. That should be all you need :)

Similar Messages

  • Printer just started feeding a blank page after some, but not all printed documents

    Printer just started feeding a blank page after some, but not all printed documents

    Hi @cam21 ,
    I understand that you are having issues printing, after some documents you are getting blank pages. I would be happy to help you.
    I would do a hard reset to see if that will resolve the issue.
    Leave the printer on and unplug the power cable from the printer and wall outlet for 60 seconds.
    Then reconnect the power cable to the printer and wall outlet rather than a surge protector.
    This ensures the printer is receiving full power and may help this situation.
    What application are you printing from?
    It may be a setting in the application.
    Does this happen from all applications?
    Download and run the Print and Scan Doctor. It will diagnose the issue and might automatically resolve it. http://www.hp.com/go/tools>Using HP Diagnostic Tools for HP Printers in Windows.
    How is the printer connected? (USB/Ethernet/Wireless)
    What were the results when you ran the Print and Scan Doctor? (did it print or scan, any error messages)
    If there is anything else I can help you with, just let me know.
    Have a nice day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • MS Word 2004 print/save as pdf - mysterious blank page

    Hi,
    I'm using Microsoft Word 2004 with OS 10.4.6. When I use the Save as pdf feature under the Print dialog, I keep getting blank pages in the pdf that don't appear in the Word Doc itself.
    The Word document contains 30 pages. The first page is a jpeg graphic. I managed to get it to print fine the other day, but after my wife fixed a few spelling errors, I got a blank page as the second page in the pdf. Strangely enough, there is no blank page there in Word. I turned on invisible characters in Word and couldn't find any stray characters. The first page is a jpeg graphic that takes up 75% of the page.
    All of the pages are formatted the same, portrait 8 1/2 x 11 with standard margins. Anyone have any suggestions?
    Thanks!
    Michael
    Power Mac G5   Mac OS X (10.4.6)   MS Word 2004 for Mac

    Hi,
    I tried pulling out the margins all the way the the edge, but I'm still experiencing the problem. I also tried reducing the image size significantly with no success. Any suggestions?
    I also tried deleting the image. With the image gone, the extra page goes, too. The page with the section break is still there but mysterious page #2 is gone. When I import the image again, though, I re-create the problem.
    I just realized I didn't try the 'Use Printer metrics to layout document' that Paul suggested and might look into that.
    Any other suggestions? I hesitate to do it because the document is somewhat elabourate, but I might try rebuilding the first few pages in a new document to see if I add the image first and then add the text if it will solve the problem.
    One other question. When I reveal invisible formatting, it does show two paragraph marks in the footer. This is the same for all footers on every page in the entire document. Could that be causing the problem? If so, do you know if it is possible to delete only the footer on the first page?
    One other clue: I used to have a graphic on the back page and now that I think of it, there was a blank page after it, too. It sure sounds like your tiling description...
    Thanks again for your help.
    Michael

  • Printing a project with about 500 pages

    Hello,
    the company I'm working for is currently discussing using robohelp for the technical documentation. So now I'm trying to find out, if robohelp really suits our needs or not. Currently I'm testing robohelp 9 on a windows xp system with word 2010.
    In the documentation for robohelp it says, that one should not print documents with more than 100 pages. So I tried to print separate documents, but couldn't generate a suitable TOC - the result was simply a document, stating, that a TOC couldn't be generated, which won't be a acceptable output. My question is: how can I generate a TOC though printing several small chapters of the document?
    Or is it possible to print a project with about 500 pages without using those single documents?
    (Up till now, it was no problem for me, to generate a suitable printing documentation, but I'm not sure, if this will still work, when the project is complete and then contains about 500 pages.)

    Hi Feebeegeebee,
    thanks a lot for your answer!
    Well, I tried to generate individual documents by using the flag "individual documents" in the printing config... but then the TOC is printed separately and therefore doesn't contain anything at all...
    If you're generating those separate documents, then how do you get a suitable TOC? (Especially if you don't intend to make different books and therefore the pages should be numbered as if they would all belong to the same document). And what about the links... do they still work if one part of it is generated in a different document?
    Regards
    Gr33bo

  • Problem with a blank page at the end.

    Hi,
    I have a report. That comes up with a blank page at the end of the report when the report generates the output in the report builder. Also in pdf file.
    It was created by somebody earlier... and i need to fix this bug.
    Any solutions..?
    Thanks in advance.
    KK
    Message was edited by:
    KK28

    Hi
    there are a number of hits on Metalink for this...
    Subject:      Extra Page Shown At The End Of A Web Report
         Doc ID:      Note:172426.1      Type:      PROBLEM
         Last Revision Date:      04-JAN-2005      Status:      ARCHIVED
    * fact: Oracle Reports Developer 6.0.5
    * fact: Solaris Operating System (SPARC)
    * fact: Microsoft Internet Explorer
    * fact: Adobe Acrobat
    * fact: OAS
    * symptom: Extra Page Displayed At The End Of A Report Viewed on the Web
    * symptom: Only happens on one report
    * symptom: Using Times New Roman
    * symptom: Client/Server configuration works successfully
    * change: Report originally created for client/server application was moved to a web application without making any coding changes in the report.
    * cause: Bug 1386820 : HTML GENERATED ON NT AND UNIX IS DIFFERENT. ADDITIONAL BLANK LINES ON UNIX
    fix:
    Use the Report Builder on Unix to make fine adjustments in the layout to
    improve the HTML output.
    -----x------------------
    Subject:      How to set the number of rows per page dynamically in a report
         Doc ID:      Note:122714.1      Type:      SCRIPT
         Last Revision Date:      07-NOV-2000      Status:      PUBLISHED
    PURPOSE
    This article shows how to set the number of rows per page dynamically according
    to the user parameter specified.
    INSTRUCTIONS
    Follow these steps:
    1. In the Object Navigator under Data Model-->User Parameters, create an user
    parameter P_1 -- this parameter specifies the number of rows you want to
    print per page
    datatype: number.
    2. In the Data Model Editor, create the query and the layout according to your
    requirements.
    Let's assume that we have the following:
    Q_1: Select empno, deptno ename from emp
    order by deptno, ename
    G_1 has the columns empno, deptno, ename
    3. In the Data Model Editor, create the following summary columns:
    CS_numrow will be numbering the rows within the detail group
    (created within G_1).
    Set the following parameters:
    Name: CS_numrow
    Function: count
    Source: <any column that does not accept nulls> for instance, empno
    Reset at: Report
    CS_total_rows will calculate the total of rows retrieved
    (created at the report level)
    Set the following parameters:
    Name: CS_total_rows
    Function: count
    Source: <any column that does not accept nulls> for instance, empno
    Reset at: Report
    4. In the Layout Model Editor, create a Group Frame M_1 within the repeating
    frame, below the fields empno, deptno, and ename. You may have to stretch
    the existing frames to be able to fit this in.
    F_enmpno F_deptno F_ename
    --------------------------------------------- <<<< create the group
    frame here
    5. Set the properties for the Group Frame M_1 as follows:
    Print condition: First
    Object: Enclosing Object
    Sizing:
    Vertical: variable
    Horizontal: fixed
    Check the box "Page Break before".
    6. Create a Format trigger for this frame M_1 as follows:
    function M_1FormatTrigger return boolean is
    /* prints until a row number is product of P_1 */
    /* if row number is 5 and P_1 = 5, MOD is 0 */
    /* then it prints the frame, doing a page break */
    begin
    if :CS_total_rows <> :CS_numrow then -- avoiding blank page at the end
    if mod(:CS_numrow,:P_1) = 0 then
    return (TRUE);
    else
    return(false);
    end if;
    else
    return (false);
    end if;
    end;
    NOTE: This assumes that the report is tabular. If you have a break group, this
    logic can be applied for the detail group.
    REFERENCES
    Information in this article was taken from Oracle Sample Code @ Repository
    Entry #956. In order to request the binary (rdf file or .sql script), please
    log a TAR via Metalink requesting Oracle Sample Code #956
    CAUTION
    The sample program in this article is provided for educational purposes only
    and is NOT supported by Oracle Support Services. It has been tested
    internally, however, and works as documented. We do not guarantee that it
    will work for you, so be sure to test it in your environment before relying
    on it.
    -------x-------------
    the list goes on...
    Hope this helps

  • Why does printing from firefox yield a blank page?

    When printing on-line, the preview pane is blank and when selecting print, it puts out a blank page. I can print fine from Safari, but not firefox. I use a Macbook with OSX 10.6 operating system.

    It sounds like you have a driver issue.  What printer do you have?  How is it connected?  What operating system?
    Regards,
    Bob Headrick, Microsoft MVP Printing/Imaging
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Hi, I've just installed mavericks but my HPc4180 will not print and is showing a 'blank' page in previews can anyone help me?

    Hi, I've just installed mavericks but my HPc4180 will not print and is showing a 'blank' page in previews can anyone help me?

    A few suggestions for you:
    Try:
    uninstall all HP utilities or other HP apps on your Mac
    see if there is updated software on the HP website
    go to System Preferences > Printers & Scanners > Print
    control-click on your printer in the column on the left
    select "Reset Printing System..." and "reset" in the dialog that follows
    Do a factory reset on your printer
    go back to printers & scanners and it should see your printer and download a driver for it from Apple

  • My mail, which used to work, comes up with a blank page, with no escape.i no longer connects to to the internet as it once did.

    My email, which used to work, now comes up with a blank page, with no escape.

    Wayne-
    Can you get back to the home page?  If so, double click on the Home button and a row of recent Apps will line up along the bottom of the screen.  Scroll across and look for the Mail icon.  Press and hold on it until it starts to wiggle.  A red minus sign should appear on each icon.  Press the minus sign on the Mail App to remove it from the list of recent Apps.  This will stop it from running in the background.
    If you can not get back to the home page, try to reboot the iPad.  Hold both the Home and Sleep buttons for several seconds until the Apple logo appears.  Ignore the "Slide to power off" arrow.  The iPad should restart in a couple of minutes.
    Fred

  • I actually need help but cannot find the answer. Please.......Lately when open a new tab it does not open with a blank page. I don't want to set my homepage as

    I actually need help but cannot find the answer.
    Please.......Lately when open a new tab it does not open with a blank page. I don't want to set my homepage as blank as when I first open Firefox, it automatically loads my hotmail page. But then if I open other pages I don't get a blank page. Help, please?
    Thank you.
    ''[Personal information removed by moderator. Please read [[Forum and chat rules and guidelines]], thanks.]''

    hello, please refer to [[New Tab Page – show, hide and customize top sites]] in order to switch the feature off.

  • Ever since upgrading to Mountain Lion, my AOL messages sometimes, but not always open with a blank page. If I open AOL in Firefox, the messages open fine.  This does not happen with any messages by any means, and it is not any type of certain message

    Ever since upgrading to Mountain Lion, my AOL messages sometimes, but not always open with a blank page. If I open AOL in Firefox, the messages open fine.  This does not happen with any messages by any means, and it is not any type of certain message. In fact, in the same screen I can often open an email from the same sender with email intact. This is weird. Sometimes I close the page and open a new page. Sometimes that works and sometimes it does not. It is a very annoying thing.

    Hi,
    When you start Messages fro the first time you are asked for an Apple ID
    When this is verified and entered it appears in Messages Menu > Preference > Accounts and is Enabled.
    The App should have also picked on on those iChat Accounst you had before.
    These should be Enabled if they were when you last used iChat.
    Exactly which "Accounts" are logged in can be seen in Message Menu > Accounts and will include the iMessage "Account" and Bonjour.
    In the Window menu you will see CMD +0 for the Messages window and CMD+1 for the "Buddies" window which is a combined list at this stage.
    Go to the Preferences > General Section and Untick the "Collect all accounts into one list".
    This will give you separate iChat type Buddy lists.
    You can check if that account/Buddy list is set to Invisible or if in the Preferences > Accounts > Security you have settings that will block some people from seeing you as On line.
    You are saying Buddies can see you as On Line which implies they are still sending to your AIM based Names (@Mac.com is a valid AIM Screen Name)
    I am not sure from your post if you are trying to iMessage their email IDs thinking they are Apple IDs and that they are using Messages as well.
    There is no Buddy list for iMessages side
    No-one can tell you are "On Line" until they have your details in the "To" spot in Messages with the correct iMessaged contact info (iPhone Number or Apple ID)
    Obviously an Apple ID can be an email or look like one.
    In some cases they are also valid AIM Screen Names as well.
    In the case or the @mac.com name you may have linked this Apple ID to iMessages as well.
    11:31 PM      Saturday; August 11, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Lion 10.7.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Creating a template in Pages is straight-forward as answered here previously. Is there and equivalent for iBooks Author which can start with a blank page and build up the template as required? or can one only adapt a ready made template?

    Creating a template in Pages is straight-forward as answered here previously. Is there an equivalent for iBooks Author which can start with a blank page and build up the template as required? or can one only adapt a ready made template? This has proved unsatisfactory to me so far. Lines are left in etc.

    There are two basic menus for fonts - one from the main menu bar and one from the toolbar. You can also bring up the font manage dialog.
    I don't recommend trying to hard to force an otherwise foreign font, as it inevitably needs to be usable/supported on iOS as well, and that can get tricky w/3rd party fonts, as an example, even with the expanded font support in the latest iBA.
    If you need to discuss fonts more, I suggest starting a new thread....preferably with a slightly more brief title, thanks.

  • I updated safari and now it opens with a blank page.  I can open a page after that but my homepage doesn't open.

    When I launch safari it opens with a blank page.

    Hey mate,
    I was having the same problem. If you upgraded to Lion - apparently there is a 'general tab' in the system preferences that has a box that you need to un check. (The box says something about restoring all last windows from last session)
    If you updated Safari but are not using Lion, here is how to fix it. Simply delete this item fromyour Mac HD and restart Safari.
    [USERHOME]/library/preferences/com.apple.safari.plist
    Hope this helps... It worked for me!

  • My safari opens with a blank page and closes back. What should I do?

    My safari opens with a blank page and closes back. What should I do

    Hi there,
    I would recommed trying this: force close the Safari application and then reset the iPhone.
    -Griff W.

  • I have install io6 and now Music doesn't work, sometimes it stay with a blank page with no possibility to press anithing, sometimes it crash. I have match music active with more than 15000 title. Someone could help me?

    I have install io6 and now Music doesn't work, sometimes it stay with a blank page with no possibility to press anithing, sometimes it crash. I have match music active with more than 15000 title. Someone could help me?

    What is your current Flash Player version: http://helpx.adobe.com/flash-player/kb/installation-problems-flash-player-windows.html ?
    What is your display adapter, driver version & date?  See http://forums.adobe.com/thread/945765

  • Does anybody can reopen Safari 5.1 on Lion (Grrrr) with a blank page ?

    Since I installed the Lion with Safari 5.1, in spite of the preferences multiple manipulations, Safari does not reopen with a blank page !
    Help please.

    Thank you It seems that only the Shift key also works.
    Best regards.

Maybe you are looking for

  • KM Scheduler Task - Service user

    Dear all, I created a scheduled task in the NWDS and deployed the par and configured the time table for it. The task is running every minute, so it's all working. Now i'm wondering, is it possible to set the user that executes the task somewhere? lik

  • Itunes syncing problems

    i tried to synce my ipod with itunes and its keeps popping up a window saying " Songs on the ipod cannot by synced because all of the playlists selected for syncing no longer exist" can anyone help me im going on a raod trip tomorrow, I need songs in

  • I want to get rid of the alert box that keeps coming up that says the server at .... is taking too long to respond

    I would rather it just keep trying to connect rather than continuously pop that stinking box up. It's very annoying

  • Rotate view tool over mouse center?

    Hello all! As the subject states - is there a way to use rotate view tool so that it's center of rotation is on the mouse / cursor location? I have tried different key command combinations and no go. If this is not possible at this point, then I woul

  • Why does my iPad 3 fail to connect to the Internet via a MiFi 4510L?

    On Sunday, I ran many tests under the guidance of a senior Verizon engineer to try to determine why the Verizon MiFi4510L mobile hotspot will not connect to the network on a third-generation iPad. In the course of our tests, we: 1. Updated the firmwa