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 2 of 2

Thread: printing

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default printing

    how can i print a jframe containing objects on a A4 paper(source code)


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    25
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: printing

    hi

    create a print button
    JButton printButton = new JButton("Print");
    printButton.addActionListener(new GUIWindow); (where guiwindow is the class that contains your frame and its object)

    then add event listener
    public void actionPerformed(java.awt.event.ActionEvent evt ) throws PrinterException
    {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    boolean ok = job.printDialog();
    if(ok)
    {
    job.print();
    }

    }

    hope this solves your problem

Similar Threads

  1. Running the try before printing something?
    By Purple01 in forum Loops & Control Statements
    Replies: 2
    Last Post: September 25th, 2012, 04:31 AM
  2. Need some help printing out my maze!
    By erock618 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 3rd, 2012, 04:50 PM
  3. Jtable printing!
    By Vagelism22678 in forum AWT / Java Swing
    Replies: 0
    Last Post: April 20th, 2012, 01:18 PM
  4. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM