-
Bug
-
Resolution: Fixed
-
P4
-
unknown, 1.1
-
b01
-
sparc
-
solaris_2.5.1
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2014523 | 1.2.0 | Brian Klock | P4 | Resolved | Fixed | 1.2beta4 |
Name: sgC58550 Date: 03/17/97
I got a run-time error when trying to print a component that I can
paint just fine. I get the same behavior on both Solaris and Windows 95.
The following is the errors I get on Windows 95. The Solaris messages
are similar.
Exception occurred during event handling:
java.lang.NullPointerException:
at java.util.Hashtable.get(Hashtable.java:225)
at sun.awt.windows.WFontMetrics.getFontMetrics(WFontMetrics.java:186)
at sun.awt.windows.WGraphics.getFontMetrics(WGraphics.java:115)
at java.awt.Graphics.getFontMetrics(Graphics.java:195)
at DrawingArea.paint(DrawingArea.java:11)
at java.awt.Component.print(Component.java:1139)
at dareout.actionPerformed(dareout.java:41)
at java.awt.MenuItem.processActionEvent(MenuItem.java:336)
at java.awt.MenuItem.processEvent(MenuItem.java:307)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:144)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:60)
Here is the abbreviated source code that generated the error. I had these
in two files.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public final class dareout extends Frame implements ActionListener {
private DrawingArea draw_here;
public void makeMenuItem (Menu menu, String name) {
MenuItem mi;
mi = new MenuItem (name);
mi.addActionListener (this);
menu.add (mi);
}
public dareout (String ftitle) {
super(ftitle);
MenuBar menubar;
Menu file, actions, display;
file = new Menu ("File");
makeMenuItem (file, "Print");
makeMenuItem (file, "Exit");
menubar = new MenuBar ();
setMenuBar (menubar);
menubar.add (file);
draw_here = new DrawingArea ();
add (draw_here);
setBackground (Color.white);
pack ();
setSize (new Dimension (1026, 749));
}
public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof MenuItem)
if (e.getActionCommand().equals("Print")) {
PrintJob pj = getToolkit().getPrintJob (this,
"Printing Test", (Properties)null);
if (pj != null) {
Graphics pg = pj.getGraphics();
if (pg != null) {
draw_here.print (pg);
pg.dispose ();
}
pj.end();
}
}
else if (e.getActionCommand().equals("Exit"))
System.exit (0);
}
public static void main (String[] args) {
dareout f;
f = new dareout ("dareout");
f.show ();
}
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public final class DrawingArea extends Canvas {
float left = 0f, right = 1016f, top = 0f, bottom = 688f;
public void paint (Graphics g) {
int stringwidth, stringheight;
stringheight = (g.getFontMetrics()).getHeight();
stringwidth = (g.getFontMetrics()).stringWidth("SAMPLE TITLE")/2;
}
}
I tend to suspect there isn't a bug in my code. Since the component
paints ok, I would expect it to print ok.
company - Cummins Engine Company , email - ###@###.###
======================================================================
- backported by
-
JDK-2014523 Run-time error with FontMetrics when printing
- Resolved
- duplicates
-
JDK-4040612 can't print Help->Remotely Debugging a Program help page
- Closed
- relates to
-
JDK-4281463 NullPointerException occurs in beening invoked "drawString" method on printing.
- Resolved