-
Bug
-
Resolution: Fixed
-
P3
-
1.1.2, 1.1.5, 1.2.0
-
b01
-
x86, sparc
-
solaris_2.5, solaris_2.5.1, windows_95
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2019028 | 1.2.0 | Robi Khan | P3 | Resolved | Fixed | 1.2beta4 |
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();
}
}
}
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();
}
}
}
- backported by
-
JDK-2019028 Print doesn't work for lightweight components
-
- Resolved
-
- duplicates
-
JDK-4100858 JFrame.printAll() leads to NullPointerException
-
- Closed
-
-
JDK-4073895 printAll causes NullPointerException when used on Component derived class
-
- Closed
-