Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:49:42+00:00 2026-06-06T01:49:42+00:00

I am making the application for printing the content of JFrame .It works properly

  • 0

I am making the application for printing the content of JFrame .It works properly but my problem is that I have to call that application on “Print” JButton which is on different form such as Print JButton is on Form_1.java and Printing content is on Form_2.java…
I am Using ActionListener on Print Button but it not Work..
pls help me my project is on deadline pls…
I posted My code Here:

public class PrintUI implements Printable, ActionListener {
    JFrame frameToPrint;

    public int print(Graphics g, PageFormat pf, int page) throws
            PrinterException {
        if (page > 0) {
            return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D) g;
        g2d.translate(pf.getImageableX(), pf.getImageableY() - 55);
        frameToPrint.setVisible(true);
        frameToPrint.print(g);
        return PAGE_EXISTS;
    }

    public void actionPerformed(ActionEvent e) {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(this);
        boolean ok = job.printDialog();
        if (ok) {
            try {
                job.print();
            } catch (PrinterException ex) {

            }
        }
    }

    public PrintUI(JFrame f) {
        frameToPrint = f;
    }

    public static void main(String args[]) {

        final JButton printButton = new JButton("Print");
        UIManager.put("swing.boldMetal", Boolean.TRUE);
        JFrame f = new JFrame("GatePass");

        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        Font f1 = new Font("Times New Roman", Font.BOLD, 12);

        printButton.setVisible(true);
        JLabel label1 = new JLabel("Vision Techno Solutions", JLabel.CENTER);
        label1.setBounds(30, 30, 200, 40);
        JLabel label2 = new JLabel("Batch No:");
        label2.setBounds(10, 70, 80, 20);
        JLabel label3 = new JLabel("Date and Time:");
        label3.setBounds(10, 100, 120, 20);
        JLabel label4 = new JLabel("Visitor's Name:");
        label4.setBounds(10, 130, 120, 20);
        JLabel label5 = new JLabel("Concern Person:");
        label5.setBounds(10, 160, 120, 20);
        JLabel label6 = new JLabel("Purpose of Visit:");
        label6.setBounds(10, 190, 120, 20);
        JLabel label7 = new JLabel("Manager's Sign");
        label7.setBounds(140, 230, 120, 20);
        JLabel label8 = new JLabel("Visitor's Sign");
        label8.setBounds(10, 230, 120, 20);

        printButton.addActionListener(new PrintUI(f));
        f.setSize(300, 350);
        f.setLocationRelativeTo(null);
        f.add(printButton, BorderLayout.SOUTH);
        f.setResizable(false);
        f.setVisible(true);
        printButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                printButton.setVisible(false);
            }
        });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:49:45+00:00Added an answer on June 6, 2026 at 1:49 am

    Not sure what exactly you are trying to do here.

    You said that you are trying to print another Frame but

    printButton.addActionListener(new PrintUI(f));
    

    indicates you are adding PrintUI class to print the current frame.

    If you want to print another frame, first create another frame in your code, make it visible, and then pass the new frame to PrintUI(), that should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am making application in c#. In that implication i have string which contain
I am making an application with Java Swing and i have a problem. I
I have been making application in which i click on image and new window
I am making an application in Python which collects data from a serial port
I am making an application in Silverlight 3.0. In that application i am using
In our web application, we have print functionality for a couple of our pages
Currently, I have an asp.net web application that links to another page. The enduser
Hi I am making application using phone gap in which certain html pages in
i am making application in c#.In that application i am using Code as private
I am making a QT application that updates the window based on the information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.