How to printa frame or a dialog

till now i have constructed JFrames andJDialogs in my project , now i would like to give an option to print the same , using a button at teh bottom of teh frame or dialog...how can i do it .....????

1) create: class WFrame extends JFrame implements Printable
2) import
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.lang.reflect.*;
import java.awt.datatransfer.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
3) add these 3 methods to your class WFrame
     public void onPrint() throws PrinterException {
          PrinterJob printJob = PrinterJob.getPrinterJob();
          printJob.setPrintable(this);
          PageFormat pf = printJob.pageDialog(printJob.defaultPage());
          if (printJob.printDialog())
               printJob.print();
     public int print(Graphics g, PageFormat pg, int i) throws PrinterException {
          int no = 1; //getNumberOfPages();
          if (i>-1 && i<no) {
               g.translate((int)pg.getImageableX(), (int)(pg.getImageableY()+(pg.getImageableY()+pg.getImageableHeight())*i));
               g.setClip(0, 0, getSize().width, getSize().height);
               paint(g);
               return PAGE_EXISTS;
          return NO_SUCH_PAGE;
     public void onCaptureScreen(String filename) throws IOException, FileNotFoundException, AWTException {
          FileOutputStream file = new FileOutputStream(new File(filename));
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file);
          Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
          encoder.encode(new Robot().createScreenCapture(rectangle));
          file.close();
4) make code to call thoses methods

Similar Messages

  • How to print frame with no values?

    Using Reports 6 (Developer 10g). In data model, I have a parent and child table connected through data link. In layout model, the child record is inside repeating frame. When child record is missing, nothing gets displayed in that frame. I still need labels to display, even though there are no values for the fields. How do I do that? Thank you.

    Hello,
    Your report is group report. And there is main group repeating frame and inside that main group repeating frame there should be two frames. one for labels and one will be repeating that will be retrieving data for child group. So, now when your group frame will return record and suppose there is no record in child repeating frame then sure repeating frame will not print. But the label frame should print which is inside that main group repeating frame. Because this label frame don't have any link with that child repeating frame. Or it your report does not seems like this. Then make it like this and then try.
    -Ammad

  • When I try and print a web page in the print screen ALL the Print Frame options are greyed out. It won't let me print a page as I see it. I need to pring a page as is. How do I do it in the new 8.0??

    I go to print and try to select the radio button to print all frames, but It's not working

    The '''Print Frames''' options are greyed out unless the web page is made with Frames. I-Frames don't work the same.
    Check out this '''''frames test page''''' - http://www.draac.com/framestest.html <br />Is the '''Print Frames''' part of the print dialog box active?
    As far as printing a page as you see it, many web pages use '''print.css''' files for print-media. The print.css specifies exactly what is to be sent to the printer and it can control the formatting of the printed page.

  • Print frames is grayed out, how can I print only one GMAIL frame ?

    I would like to print the contents of a mail in gmail, and not everything around it.
    Using print frames does not seem to work, it is grayed out.
    Is there a solution for this ?
    I read somewhere that sometimes something that looks like a frame is not really a frame.
    The mail content 'frame' can be scrolled up and down, while the left (gmail info frame) and
    right (adverts) remain in place.

    Are you printing through Preview? When Firefox 29 was released some users noted that printing frames did not work if you were accessing Print through Preview. Instead, you had to access the Print dialog directly from the page, for example, by pressing Ctrl+p.
    For better results, though, could I suggest using the print-formatted version of the message? Above the message you should find a printer icon that will pop up a cleanly formatted version of the message (by default, the new window is diverted to a new tab).

  • HOW TO PRINT  THE EXCEL CELL COMMENT IN JAVA SWING FRAME ?

    How to print the excel cell comment in java swing frame
    user can print the data of cell with comment in bracket in java swing frame.
    please make one java code to read an excel spreed sheet and print the output in Java swing frame as follows
    EMP NO - 1, 2, 3
    EMP NAME - aname (amitesh:very good), bname (amitesh: average), cname (amitesh: very bad)
    EMP AGE - 11, 22, 33
    EMP DESG - ad, bd, cd
    Note: the bracket portion is the excel comments put in that cell

    hello everyone i'm new to this forum..how are you all...
    Jack Brosnan
    [mobile phone|http://www.mobilephonesforsale.net.au/apple-iphone-f-2.html]

  • How to print the output of the screen in Dialog Programming

    Hi,
    Could anybody help how to print the output of a screen in the dialog programming. i can select 'Hard Copy' option in the 'Custumizing of Local Layout' Icon in the standard tool bar. but that prints the whole screen with the toolbar. i want to print only the output which is displayed on the screen. Please help..
    Regards,
    Swathi

    Hi Swathi,
        Ok. Do One thing. Go to menu bar and select Systems -> Own pool Request -> here you get the spool number. Select it and select the option "Print Directly" in tool bar.
    Thanks.

  • How to print in java(page or whole frame with photos)

    Hell sir,
    My self kiran patel.I am going to devlop a visitor information system project for Ongc(stand-alon application)
    I want to know about below topics.
    (1) How to print simple page using printer in java.i dont know any code.
    (2) Printing page should contain the whole page which include information and photo of visitor.
    (3) how to catch the photo in data base or my frame of visitor info. which we have taken throw web-came.
    (4) can we store any image in database?
    Please help me as possible as soon.......
    kiran patel(MSc it)

    Background study -
    http://java.sun.com/docs/books/tutorial/2d/printing/index.html
    http://java.sun.com/docs/books/tutorial/jdbc/index.html

  • How to print a canvas

    HI i'm new to Photoshop element 13, and i would like for somebody to explain to me, how to print a picture unto a canvas, so that i can frame it onto a 1/2 inch wood frame. wrapped around style, it seems like i always print to big or to small??????
    Thanks

    Hi ,
    Please follow these steps in following order you will definitely end up with right result.
    1) open print dialog.
    2) select your printer.
    3) select right paper size either A4 , A3 .
    4) Click on more options .
    5) select custom print size.
    6) Enter designated size of print ex - 7 x 8 inches.
    7) Click ok and then print .
    for step 4 , 5 and 6 refer to this screenshot-

  • How to print a text in java?

    How to print a text in java?

    of corse, i have JTextField in my frame that i want to extract the text and print it on a paper with a printer.

  • How to print double sided from my Mac to my Canon MG6350

    I have looked up everywhere on the internet and youtube of how to print double sided from my Mac Book Pro. I am using OSX 10.8.5.
    All of the dicussions I have looked up before have told me to go to System Preferences>Print & Scan>Options & Supplies> Driver and then tick the little box that comes up and it will allow you to print double sided. I have tried doing this but THERE IS NO DRIVER TAB!!!
    I was just wondering if there was a solution to this as I can print double sided from my other appliences, like the PC and iPad, it is just my Mac Book Pro that doesn't work.
    It has become a big problem for me as I'm studying at college and I need to print things double sided quite regularly. I really need this to work.

    The print dialog has several drop-down menus, one of which initially shows the name of the application you're printing from. If the printer supports duplex, you can choose
    Duplex Printing & Margin
    from that menu. You should then see a checkbox marked
    Automatic Duplex Printing

  • How to print double sided with macbook pro on Samsung CLX-3180?

    Hi,
    I recently switched to using a macbook pro but cannot figure out how to print double sided/two-sided.
    The printer I am using is Samsung CLX-3180 and it allows double-sided printing. I was able to do this with my windows computer previously.
    The frustrating thing is that I see the two-sided feature but I cannot figure out how to turn it on. There is no option to change it.
    It is listed here.
    First, I go to "show presets."
    Then, I click on "copies & pages" but I cannot turn it on.
    Does anyone know how to turn it on?
    Any suggestions would be highly appreciated.
    Thanks.

    Hi nat.the.musical,
    If you are having issues selecting two-sided printing from the Print window, you may find the following article helpful (it is aimed at Mountain Lion, but should also apply to Mavericks):
    OS X Mountain Lion: If your printer has features that aren’t in the Print dialog
    http://support.apple.com/kb/PH11477
    Regards,
    - Brenden

  • How to print an html report?

    In a Test UUT's execution, the process model generates and saves a html report. How can add steps to the process model to print the report each time? I'm thinking maybe somehow using an ActiveX call to open IE and then print (1 step or 2?), but I'm a newbie to ActiveX and don't know what server/class/method to use.
    ==============================================
    David Kaufman
    LabVIEW Certified Developer
    ==============================================

    Using Microsoft Word could be a good solution if you actually have it installed in the computer. In some cases, you may not want to have that application installed in the production floor for any reason (licenses, memory space...).
    I am attaching an example that shows how to print the report automatically after testing a UUT using ActiveX to communicate with Internet Explorer. It is more likely that any machine would have this application installed since it occupies a lot less memory space and it ships with any Windows OS. Furthermore, there are just 3 steps that do the trick!
    The attached zip file contains a modified sequential model. The entry points ("Single Step" and “Test UUTs”) have one new step that calls the "Print Report" sequence (also added to the sequential model). This new sequence has ActiveX steps that call two methods of the “Internet Explorer (IwebBrowser2)”object class exported by the “Microsoft Internet Controls” automation server. These two methods are:
    1) Navigate. Allows you to select the html file to load.
    2) ExecWB with the first parameter (cmdid) set to "OLECMDID_PRINT" (prints the loaded file) and the second parameter (cmdexecopt) set to OLECMDEXECOPT_DONTPROMPTUSER" (don’t show the print dialog).
    (For more information about these methods, please refer to the MSDN Library)
    The example will print the report after each UUT is tested. The "Print Report" step is set to run just if the Report Generation is not disabled (see its preconditions).
    This is what you need to do to run the example:
    1) Copy the contents of the zip file to: \Components\User\Models\TestStandModels
    2) Make sure that the “User Components Directoty” is checked in the Search Directories.
    3) Run any sequence using Single Pass or Test UUTs.
    WARNING: There is a known issue when using the printing capabilities of the Internet Explorer. This is what is explained in the MSDN library:
    "... Internet Explorer prints in the background. This means that the print processing is actually completed asynchronously in a separate thread.Upon return from ExecWB, the print processing may continue for several seconds or even up to a minute or two based on various factors such as the size of the content and how busy your system is currently. The problem is that if you start a print job and then destroy the WebBrowser or close your application before the background thread finishes processing, the thread will abandon its work and the page may not be completely printed..."
    There are 2 approaches to work around this problem:
    1) Use a delay before destroying the WebBrowser reference (which is done in the cleanup step group of the "Print Report" sequence in the example). This is the approached used in the example. The third step in the “Print Report” sequence is a Wait step. The step is currently set to wait for 3 seconds which has worked for me for almost any report sizes.
    2)In Internet Explorer 5 you can work around this problem by sinking the OnAfterPrint event. If you have started a print job, then you should wait to release the WebBrowser until after this event has been received. If you choose this approach you could use the ActiveX events capabilities of Labview or Visual Basic to create a small program detecting this event. There's a simple sample code provided in the MSDN library for VB.
    Enjoy!
    Attachments:
    SequentialModel.seq ‏169 KB

  • How to print the picture in PDF ?

    I developed a plug-in(Annot) that dynamically display a picture according some condition in PDF,but the picture cannot be printed. How to print the picture ?

    In the print dialog, make sure that Print: Comments (which means
    annotations) is on.
    Aandi Inston

  • How to print date in cheque box in sapscript??

    Hello Guru,
    We have developed or design new form for cheque printing in sapscript
    how to print date in cheque box in sap.
    1
    6
    1
    2
    2
    0
    1
    1
    thanks in advance.
    Thanks & Regards
    Richa

    hi,
    If your requirement is to display date with box,first create a Box by using following syntax
    *   &sy-datum&
    /:  BOX XPOS '0' CH YPOS '3.65' LN WIDTH '77.50' CH HEIGHT '4.5' LN FRAME '10' tw
    then adjust the box size according to your requirement by changing xpos,ypos,width and height
    with regards
    Edited by: naresh bammidi on Dec 16, 2011 8:00 AM

  • How to print envelopes in pages, How to print envelopes in pages

    How to print envelopes in pages, How to print envelopes in pages

    I presume you are using the Pages application, is that correct?
    So start off by launching Pages and choose one of the regular envelope styles. Traditional works well for me.
    Next go to the File menu and select Page setup. From the menu that says Paper Size select Manage Custom Sizes. In the resulting dialog, there should be a button on the left labeled "+". Click it. In the Paper Size area, select Width 5 in and Height 7 in. Name the size (where it says "untitled" something descriptive like "5 x 7 envelope". Click the OK button. The Paper Size menu here should now say the description you gave it. Click OK again. Your work area should now be a 5 x 7 envelope.
    Best of luck.
    PS If you are using Word or some other program, the process is probably the same or very similar.

Maybe you are looking for

  • My iMessage won't open, it just crashes.

    I have the iPod 5 with IOS7. And recently after I sent my sister a few dozens of pictures it crashed. I thought maybe because of the overload photos I must of sent; there were a lot. So when I went back to iMessage it won't open. It just keeps crashi

  • Error While Creating user in Portal

    Hai Experts... Errored occured while creating User in portal. Error : Error  occured due to persistance: contact administrator. Since i have created user in J2EE_ADMIN which has Administrator Role. i am facing this issue. Kindly help me in this issue

  • Best way to replace hard drive with Time Machine

    Hello, I searched dozens of threads before posting but I didn't find my specific topic. I have a G5 (single CPU) with two internal hard drives plus one external drive. The original hard drive is only 80gb and it has been quite full for several years

  • Problem Displaying generated Markup File (CLOB column)

    Dear Colleague, I am attempting to display the results of a generated Markup File in a Forms Text Item. The code (Below) is in a WHEN-BUTTON-PRESSED trigger. Step 1: generates the markup file and stores it in the MARKUP_DOCUMENTS table. Step 2: Copie

  • Error when opening & trying to install update

    When updating premiere pro CS5 on a mac running OS X 10.9.5, updater gives following message: "Adobe Premiere Pro CS5 v5.0.4. There was an error downloading this update. Please quit and try again later." ... Why thank you for that info. When opening