-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
x86
-
windows_nt
Name: boT120536 Date: 12/16/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Here is source:
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.net.URL;
import javax.swing.*;
class MyButton extends JButton
{
public MyButton(String label)
{
super(label);
}
}
/**
* <pre>
* Test for printing. This sample hangs if ImageIcon is not initialized
* with valid file from URL.
* <pre>
* @author Stoil Valchkov
*/
public class printbutton extends JPanel implements ActionListener, Printable {
public printbutton()
{
try
{
ImageIcon icon = new ImageIcon(new URL("file:/c:/temp/test.gif"));
JLabel testLabel = new JLabel(icon);
testLabel.setText("This is test Label");
setBackground(Color.white);
MyButton b = new MyButton("MyButton");
b.addActionListener(this);
add(b);
add(testLabel);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
if (pi >= 1)
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
Font f = new Font("Courier", Font.PLAIN, 12);
g2.setFont (f);
paint(g2);
return Printable.PAGE_EXISTS;
}
public void actionPerformed(ActionEvent e)
{
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
try { printJob.print(); } catch (Exception PrintException) { }
}
public static void main(String s[]) {
RepaintManager.currentManager(null).
setDoubleBufferingEnabled(false);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
Frame f = new Frame("printbutton");
f.addWindowListener(l);
f.add("Center", new printbutton());
f.pack();
f.setSize(new Dimension(400,300));
f.show();
}
}
When button is pressed, if URL is not valid there is no way to print something.
Here is thread dump:
Full thread dump:
"Thread-1" prio=5 tid=0x784110 nid=0x162 waiting on monitor [0..0x6fb38]
"AWT-Windows" prio=5 tid=0x777a80 nid=0x161 runnable [0x902f000..0x902fdc8]
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(WToolkit.java:186)
at java.lang.Thread.run(Thread.java:484)
"SunToolkit.PostEventQueue-0" prio=5 tid=0x776550 nid=0x16e waiting on monitor [
0x8fef000..0x8fefdc8]
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:420)
at sun.awt.PostEventQueue.run(SunToolkit.java:496)
"AWT-EventQueue-0" prio=7 tid=0x776f20 nid=0x12e waiting on monitor [0x8faf000..
0x8fafdc8]
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:420)
at sun.java2d.PeekGraphics$ImageWaiter.waitForDimensions(PeekGraphics.ja
va:1848)
at sun.java2d.PeekGraphics$ImageWaiter.<init>(PeekGraphics.java:1832)
at sun.java2d.PeekGraphics.drawImage(PeekGraphics.java:942)
at javax.swing.ImageIcon.paintIcon(ImageIcon.java:307)
at javax.swing.plaf.basic.BasicLabelUI.paint(BasicLabelUI.java:152)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:39)
at javax.swing.JComponent.paintComponent(JComponent.java:398)
at javax.swing.JComponent.paint(JComponent.java:739)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at printbutton.print(printbutton.java:61)
at sun.java2d.RasterPrinterJob.printPage(RasterPrinterJob.java:677)
at sun.java2d.RasterPrinterJob.print(RasterPrinterJob.java:342)
at printbutton.actionPerformed(printbutton.java:69)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:14
50)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3717)
at java.awt.Component.processEvent(Component.java:3546)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:912)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:10
3)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
"Signal Dispatcher" daemon prio=10 tid=0x768070 nid=0x142 waiting on monitor [0.
.0]
"Finalizer" daemon prio=9 tid=0x766b20 nid=0x172 waiting on monitor [0x8d8f000..
0x8d8fdc8]
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:108)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:123)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:162)
"Reference Handler" daemon prio=10 tid=0x765830 nid=0x15b waiting on monitor [0x
8d4f000..0x8d4fdc8]
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:420)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:110)
"VM Thread" prio=5 tid=0x764ae0 nid=0x16c runnable
"VM Periodic Task Thread" prio=10 tid=0x768a70 nid=0xbe waiting on monitor
Program hangs in ImageWaiter.waitForDimensions.
(Review ID: 112445)
======================================================================