Can't print JFrame

Hi,
i am trying to print out a JFrame that contains other Swing and AWT components, such as JTables and menus etc.
The problem is that the options that i select from the pageformat dialog, so not get set when the printing is taking place. As a result my jframe gets cut up into 4 differnet bits and each comes out on a seperate page. I cannot specify number of copies or size of paper either. Also once the ok button is pressed on the print dialogue, then the print dialogue comes back again and i have to press Ok, or Cancel to get rid of it. My code is below, please can someone suggest anything:
]public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
          if (pi >= 1)
               return Printable.NO_SUCH_PAGE;
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(pf.getImageableX(), pf.getImageableY());
          g2.setColor(Color.black);
          paint(g2);
          return Printable.PAGE_EXISTS;
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = pjob.defaultPage();
pjob.setPrintable(TransponderGraph.this, pf);
try
pjob.print();
catch (PrinterException e) { }

Just comment this line frame.setAlwaysOnTop(x);

Similar Messages

  • Print JFrame without title bar and border

    I am trying to print out a JFrame which contains two JPanels. The following code is part of my implementation of Printable which prints the entire JFrame including the title bar and border. I've considered implementing Printable in the JPanel classes but then I don't know how I would get everything on one page as a single image. Is there some way to just print the contentPane of the JFrame?
         public int print(Graphics g, PageFormat pf, int pi)
              throws PrinterException {
              if (pi >= 1) {
                   return Printable.NO_SUCH_PAGE;
              Graphics2D g2 = (Graphics2D) g;
              double scaleX = pf.getImageableWidth()/getWidth();
              double scaleY = pf.getImageableHeight()/getHeight();
              double scale = 1;
              g2.translate((int) pf.getImageableX(), (int) pf.getImageableY());
              if (scaleX < 1 || scaleY < 1) {
                   scale = scaleX < scaleY ? scaleX : scaleY;
                   g2.scale(scale,scale);
              printAll(g2);
              return Printable.PAGE_EXISTS;
         }                    

    Thanks.
    I can get the Jframe without the title bar and I can get it to drag on the desktop with your suggestions. I still need it to have rounded edges.

  • Can we print a swing form

    hi,
    i have a question , i m making a windows based application in swings, can i print that form, reply at the earliest..
    thanks in advancee

    //or try this program, just execute it.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.BorderLayout;
    import java.awt.print.*;
    import java.awt.Dimension;
    class printtest extends JFrame implements Printable,ActionListener
    Component c;
    printtest()
    super("just test");
    setSize(300,150);
    setVisible(true);
    JPanel p1=new JPanel(new FlowLayout());
    JLabel l1=new JLabel("name");
    JTextField t1=new JTextField(10);
    JButton b1=new JButton("Print");
    b1.addActionListener(this);
    t1.setText("hai");
    p1.add(l1);
    p1.add(t1);
    p1.add(b1);
    add(p1);
    this.c=p1;
    public void actionPerformed(ActionEvent e)
    try
    print();
    catch (java.lang.Throwable exc)
    System.out.println("Printer
    Exception");
    public void print() throws java.awt.print.PrinterException {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat format = job.pageDialog(job.defaultPage());
    job.setPrintable(this,format);
    if ( job.printDialog())
    job.print();
    public int print(Graphics graphics, PageFormat pageFormat, int
    pageIndex) throws
    PrinterException {
    if (pageIndex > 0)
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) graphics;
    g2.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
    c.paint(g2);
    return Printable.PAGE_EXISTS;
    public static void main(String ar[])
    printtest t=new printtest();
    }

  • How can I print some pages from multipage report

    Hello,
    I have created a multipage report in word. I would like the user to be able to print the pages selected (as in word printing: pages: 1, 2-3); 
    I am using Office 2007 pro, the LabVIEW Report Gen Toolkit, LabVIEW 2009, and Windows XP.
    I used the suggestion in thread:
    http://forums.ni.com/t5/LabVIEW/How-can-you-print-a-single-page-of-a-multipage-report/m-p/155233 , modifying the print VI that comes shipped with LabVIEW: NI_ReportGenerationToolkit.lvlib:Word_Print.VI.
    first of all I put two integer constants on "From" and "To" in the Invoke node (PrintOut), but Labview return an error:
    Error 1015 occurred at NI_ReportGenerationToolkit.lvlib:Word_Print.vi -> NI_Word.lvclassrint Report.vi -> print2.vi
    Then I searched for PrintOut Method in word 2007 Reference guide, and I saw that for using From and To the Range field must have the string  wdPrintFromTo;
    I insert wdPrintFromTo string  in RANGE Field and tryed.... same error......
    After that I change approach; removed all constants and used the field Pages; I put a string "1-2" connected to this field and now the printer respond, but all pages was printed!
    What's wrong?
    many thanks
    Attachments:
    print2.vi ‏18 KB
    parte comune.doc ‏43 KB

    Thanks, Alex!
    ok, I try first approach in print4.vi, but Labview return an error (view jpg); if I cut From, To controls, the VI print all pages. The same things happen also if I trasform I32 in Variant.
    I don't try second approach, because at this time I have only one report
    I try also with VB macro: this is better (print3.vi) but.....if I use:
    Sub Print_Pages_From_To()
    ActiveDocument.ActiveWindow.PrintOut Range:=wdPrintFromTo, From:="2", To:="3"
    End Sub
    is ok; print the pages selected; if I use:
    Sub PrintPages()
    ActiveDocument.ActiveWindow.PrintOut  Pages:="2-3"  
    End Sub
    printer print all pages.
    what do you think?
    regards,
    Italo
    Attachments:
    print Problem.jpg ‏39 KB
    print4.vi ‏19 KB
    print3.vi ‏19 KB

  • In Ical, can you print a list view calendar without notes?

    In Ical, can you print a list view calendar without notes?

    cj,
    After selecting Calendar>File>Print...> I am presented with a Print selection pane which offers among other choices, a "List" selection:
    What do you see?

  • How can I print to hp photosmart all in one 7280 from ipad

    How can I print to hp photosmart all in one 7280 from ipad
    This question was solved.
    View Solution.

    Hi,
    Although the C7280 is not AirPrint enabled, you may still print through the local network using the HP ePrint mobile app.
    you may find the steps to get and use the app in the following document:
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02775166&cc=us&dlc=en&lc=en&product=3204785&tmp...
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • How can I print out the contents of my hardrive

    I have a hardrive with about 200 video clips and need to print the titles for cross refrerencing. I was just going to "grab" screenshots but this will take about ten sheets of paper. How can I print out a list of all the files on the drive?

    I tried this Finder drag method & discovered that it is very important to set the blank TextEdit document to plain text before the drag (from the format menu or with Cmd-shift-t). If you don't, TextEdit attempts to load the content of the files!
    Once I discovered this, I tried the method with Find (Cmd-F) results & it works for that, too. This means that by choosing the right combination of search location(s) & search criteria, you can extend the method to filter the list to just about any files you want, which could be very handy.
    For instance, set the "Kind" criteria to "QuickTime Movie" & location to "Computer" & you get a list of every QT movie. Or set the search location to the folder containing the movies of interest & you get all of them, including ones in subfolders. You could also use the 'date created' or other search criteria to filter the list to a specific subset of movies (or whatever).
    If you need to do this often, you could create one or more 'Smart Folders' with the criteria preloaded for each search.
    The only drawback I see for either Finder based method is the full path one. If you are getting results from just one or a few folders, Find & Replace can delete any of the path name fairly easily, but it becomes a chore if there are a lot of different ones. Some other text editor, like TexEdit Pro, that supports grep searches would be handy here, but since I'm not up to speed on grep, someone else will have to explain how to use it for this, if they want.

  • How can I print ONLY the active document?

    Whenever I go to File/Print the darn PSE 9 program sends all of the working files in the bin to the printer. I've searched online for 2 hours now looking for an answer.
    I like to work with having several to many files in the 'bin' and prefer to only print the active file I'm currently working on without having to close the 'working files' before I can print. How can I print ONLY the active document or file in the project bin? Please help, I've upgraded from PSE 3 to PSE 9 and really like the updated features, but this one pain in the neck default is getting the best of me.

    Thanks for your help, that works nicely. It is good to have control of the printer again.

  • How can i print out the waveform chart?

      hello everybody,
    how can i print out the "waveform chart". can i do it just push the button. ( example; stop button is stop the program etc..)
    i checked the NI examples but i can't understand. i'm new to the Labview.
    pls help me.
    i added the my program
    look forward your reply
    regards from turkey...
    Message Edited by hknmkt on 05-29-2008 04:15 AM
    Attachments:
    29.05.2008_11.vi ‏37 KB

        hi jim,
    i tried the program but it's not running. When i run the program, it's print out without run the program
    i added the printed file.
    look forward your reply
    hakan
    Attachments:
    error8.JPG ‏8 KB

  • How can I print with the black and white cartridge only?

    I am trying to print using the black and white cartridge only because magenta is out of ink but I'm getting the following error message in HP Photosmart C7200 series print dialog:
    The printer is out of ink.
    The following ink cartridges are empty: Magenta. Replace these ink cartridges to resume printing.
    How can I print with the black and white cartridge only?
    Mac OSX 10.7.3
    HP Photosmart C7280 (7200 series)
    This question was solved.
    View Solution.

    I am absolutely disgusted by this; clearly a scam from HP to make more money by selling extra ink cartridges!!  I will make sure to never buy any products from the shoddy rip off merchants at HP ever again!!
    You should be ashamed!!

  • How can i print an Excel file when in the full screen mode (no print options on toolbar or right clk

    using Vista, sometimes after creating and saving an excel file, the document is not visible when the file is reopened.
    selecting full screen mode makes the document visible, but the toolbars disappear and the print option does not show up on a right click.  How can i print the document and see the document in some other mode than full screen?

    In order to print, you can click the CTRL+P keys to launch the print dialog,
    Regarding the missing toolbar, try clicking the ALT key to shouw the software menu, then look around under the view option for any available toolbar settings,
    If you cannot find it, i would recommend you to try the Microsoft support forums, as they have some more knowledge with their software features
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • How can i print all the contect of the code in sapscript window ? ?

    how can i print all the contect of the code in sapscript window ? ?

    Hi,
    Do you mean that you want to print the ABAP code to SAPscrip form ?
    Svetlin

  • How can i print all the tab pages not just the first page (tab)

    how can i print all the tab pages not just the first page (tab)

    You would need to do this programmatically. Here's one way:
    Attachments:
    Example_VI_BD6.png ‏3 KB

  • How can i print just one page of photo book without printing the entire book

    how can i print just one page of photo book without printing the entire book

    Jim,
    Take heart.  We can help.
    First turn on page view so you can see how the content of your sheet fits on the page(s).  A Numbers document contains sheets (listed on the left) which in turn contain tables, charts, text, and graphics.  Select the sheet you want to print on the left, then enable page view by selecting the menu item:
    "View > Show Print View":
    Now you should see your content and how it fits on one, or more, pages.  If thie content is too big for one page use the controls and the bottom left of the window to expose the sheet controls:
    Here a table is too big to fit on one page:
    slide the "Content Scale" slider so the content fits:

  • How can I print just a part of the page and not the full page with Adobe Reader v 10.1.2?

    how can I print just a part of the page and not the full page with Adobe Reader v 10.1.2? I need to print a engineering print with lot of information but information is too small in letter size and I don't have a plotter.

    Two ways to print a portion of a page: zooming or using the Snapshot Tool.
    ZOOMING:
    Zoom into the area you want to print.
    Click the Print icon.
    Under "Pages to Print", make sure "Current view" is selected under "More options" (you may need to click "More options" to open it).
    If you aren't satisfied with the preview, try clicking "Fit" under the Size button.
    SNAPSHOT
    Choose Edit > Take A Snapshot.
    Drag a rectangle around the area you want to print. 
    Click the Print icon.
    Under "Pages to Print", make sure that "Selected Graphic" is selected under "More options".
    To enlarge the snapshot to fit the sheet of paper, choose "Fit" under the Size button.
    Hope this helps!

Maybe you are looking for

  • ICC profiles missing from the menu (InDesign 6.0.4.)

    After the update to InDesign 6.0.4 icc profiles saved in Macintosh HD/Library/ColorSync/Profiles does not list in InDesign profiles menus. But they show up in Photoshop CS4. Why? I've tried to reset the InDesign's preferences folder and fixed file pe

  • Automated Regression Testing

    Apologies for putting a more advanced question in a general forum but there is no Topic for QA/Testing (that I know of). Okay, I've been tasked with finding a solution for fully automated unit, component, system, and regression testing. I realize tha

  • How do i burn dvd from iMovie

    How do I burn dvd from iMovie.  iMac has yesomite installed.

  • Why can't I get Elements 12 to connect and verify?

    Hi I bought a copy of elements and when I start the program it wants to verify and then tells me to connect to the inetrnet. My PC is connected as soon as it is powered up so it should not have any problem but it apparently cannot see the connection

  • Premiere Pro CC 2014 not optimized for iMac 5K graphics card?

    I have the new iMac 5k with the AMD Redeon R9 M295X 4 GB GDDR5 graphics card. In Premiere Pro CC 2014 (updated to the latest version), when I go to "project settings" and select "Mercury Playback Engine GPU Acceleration," I get a pop-up window that r