Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4111262

Print doesn't work for lightweight components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.7
    • 1.1.2, 1.1.5, 1.2.0
    • client-libs
    • b01
    • x86, sparc
    • solaris_2.5, solaris_2.5.1, windows_95
    • Verified

        Print doesn't work for swing components. It throws NullPointerException. If replace swing components with AWT compoents, it will work.

        Try the following test case to print a JFrame which contains swing components.

        import java.awt.*;
        import java.awt.event.*;
        import java.util.*;
        import com.sun.java.swing.*;

        public class Test extends JFrame implements ActionListener{

          public static void main(String[] argc){
            Test T=new Test();
            T.setSize(new Dimension(200,200));
            T.setVisible(true);
          }

          public Test(){
                this.getContentPane().setLayout( new BorderLayout());
            this.getContentPane().add("North",new JLabel("Hello!"));
            JButton b=new JButton("Print");
            b.addActionListener(this);
            this.getContentPane().add("Center",b);
          }

          public void actionPerformed(ActionEvent e){
            String com=e.getActionCommand();
            if (com.equals("Print")){
              PrintJob pj= getToolkit().getPrintJob(this,"Print test!",new Properties());
              Graphics g=pj.getGraphics();
              printAll(g);
              g.dispose();
              pj.end();
            }
          }
        }


              rkhansunw Robi Khan (Inactive)
              pchusunw Patience Chu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: