Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to Print JFrame content using NetBeans Java Swing

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post How to Print JFrame content using NetBeans Java Swing

    I am developing a program in netbeans forms. I've got to a point where I will click a jButton to print the content of either JFrame or JPanel.
    I am using Netbeans forms to develop the project, Please could anyone help me sove this issue?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 832 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to Print JFrame content using NetBeans Java Swing

    If you have not read the following I recommend it:
    Lesson: Printing (The Java™ Tutorials > 2D Graphics)
    If you have read it, I recommend posting what you have tried as an SSCCE with a specific question about your code.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to print JFrame content

    I am writing a software that allows the user to print a receipt. The receipt has been designed in a JInternal Frame enclosed in JPanel. I want to be able to print the receipt. The code i wrote when a click on the print button, it just triggers the frame without showing print dialog. Since I am new in Java and netbeans I am finding it very difficult to accomplish the project which I must submit on Monday. I used netbeans forms to design the project and this is my Print code. I know something is wrong somewhere along the code but I cannot figure it out. I want somebody to help me accomplish this task.

    private void jButton11ActionPerformed(java.awt.event.ActionEven t evt) {

    PageFormat pf = new PageFormat();
    Graphics Graphic=jInternalFrame2.getGraphics();
    Graphics2D g2d = (Graphics2D)Graphic.create();
    g2d.translate(pf.getImageableX(), pf.getImageableY());

    print(g2d.create());
    }
    Thank you

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: How to Print JFrame content using NetBeans Java Swing

    Threads merged and moved.

    Please do not start duplicate threads on the same topic.

    Please post your code using code or highlight tags as explained near the top of this topic.

    What has changed since your first post, if anything? Did you make any progress after following copeg's suggestion?

Similar Threads

  1. Replies: 1
    Last Post: July 11th, 2014, 12:48 PM
  2. JAVA SWING - Print
    By SadhanaMUlik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2013, 04:55 AM
  3. print a form in java netbeans
    By seemarani in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 2nd, 2013, 08:45 AM
  4. Replies: 1
    Last Post: December 3rd, 2012, 02:35 PM
  5. Problem with java swing JButton in Netbeans IDE
    By vrp in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 12th, 2011, 11:38 PM