|
Quick Lists
|
|
Bug ID:
|
6189824
|
|
Votes
|
0
|
|
Synopsis
|
REGRESSION: HeadlessException in JComponent.paint() when java.awt.headless=true
|
|
Category
|
java:classes_swing
|
|
Reported Against
|
b03
, b33
, b38
|
|
Release Fixed
|
mustang(b46)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
6259207
,
6279359
,
6312315
|
|
Submit Date
|
03-NOV-2004
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
And "1.4.2_06-b03"
ADDITIONAL OS VERSION INFORMATION :
SunOS SUNSVR6.americas.cpqcorp.net 5.9 Generic_112233-10 sun4u sparc SUNW,Sun-Fire-V440
customer Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Running with the -Djava.awt.headless=true, I try to call JComponent.setBounds(), the headless exception occurs during JComponent.paint().
I have tested with jdk1.4.1_05 and it works fine, but version 1.4.2_06 and 1.5.0 both throw the HeadlessException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. javac Headless.java
2. java -Djava.awt.headless=true Headless
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Paint worked ... ok
ACTUAL -
java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(Headles
sGraphicsEnvironment.java:65)
at javax.swing.RepaintManager.getVolatileOffscreenBuffer(RepaintManager.
java:583)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4869)
at javax.swing.JComponent.paint(JComponent.java:993)
at Headless.main(Headless.java:27)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Headless {
public static void main( String[] args ) {
BufferedImage img;
try {
img = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB );
Graphics2D graphics = img.createGraphics();
graphics.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
graphics.setColor( Color.white );
graphics.fillRect( 0, 0, 600, 400 );
JComponent comp = new JPanel();
comp.setBounds( 0, 0, 600, 400 );
// Un-comment the following line to allow it work on jdk1.4.2
// and jdk1.5.0
//comp.setDoubleBuffered( false );
comp.paint( graphics );
System.out.println( "Paint worked ... ok" );
}
catch ( Exception e ) {
e.printStackTrace();
System.exit( 1 );
}
System.exit( 0 );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only workaround I found is to not set -Djava.awt.headless=true and to use Xvfb.
Release Regression From : 1.4.1_05
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
xxxxx@xxxxx 11/3/04 00:47 GMT
|
|
Work Around
|
Call RepaintManager.currentManager(null).setDoubleBufferingEnabled(false);
xxxxx@xxxxx 2005-07-01 21:20:19 GMT
|
|
Evaluation
|
Looks like a swing issue. VolatileImages shouldn't be used in a headless environment.
xxxxx@xxxxx 11/3/04 18:09 GMT
The checks for headless have already been added, but casts in RepaintManager to SunToolkit are not valid if headless. If headless BufferStrategyPaintManager should not be used. The fix will turn off use of BufferStrategyPaintManager if headless, and all will work again.
xxxxx@xxxxx 2005-07-01 21:20:19 GMT
Posted Date : 2005-07-01 21:20:19.0
|
|
Comments
|
Submitted On 19-JUL-2007
Hi,
How can i run following program without setting DISPLAY environment variable.
I am running this program from Solaris 5.9 through a batch file.
public FontTest() {
try{
setSize(width, height);
in = new FileInputStream("./CofCTemplate.jpg");
bufferImage = new BufferedImage(800,500,BufferedImage.TYPE_BYTE_GRAY);
bufferImage = ImageIO.read(in);
bufferGraphics = bufferImage.getGraphics();
bufferGraphics.setColor(Color.red);
bufferGraphics.setFont(font);
bufferGraphics.drawString("Testing", 230, 642); //write mktPart onto template
bufferGraphics.drawString("O", 880, 642);
File saveFile = new File("./temp.jpg");
ImageIO.write(bufferImage, "jpg", saveFile);
}
catch(Exception e)
{
e.printStackTrace();
}
}
/* public void paint(Graphics g) {
System.out.println("Inside Paint");
g.drawImage(bufferImage, 0, 20, null);
g.setColor(Color.red);
g.setFont(font);
g.drawString("TESTING", 30, 110);
} */
Thanks,
Rashmi
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |