-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
1.4.2
-
x86
-
windows_xp
Name: jk109818 Date: 08/28/2003
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When XP visual themes are used the text which overlays the visual theme
is not rendered properly when the component is printed. If overlapping
components are used, any text from another component which overlaps the
area used by a visual theme graphic is also printed incorrectly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Included is a sample of a printableFrame application, posted to the forums by
Denis Cau, which has been modified to set windows look and feel.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect text to be printed on the button when visual themes are enabled.
ACTUAL -
Text is not printed. On more complex applications with multiple components,
garbage gets rendered instead of the text.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
import javax.swing.*;
public class PrintableFrame extends JFrame implements Printable, Pageable {
private PageFormat defaultPageFormat = new PageFormat();
public PrintableFrame()
{
super("test frame printing");
JButton printButton = new JButton("Press to print");
printButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
startPrinting();
}
});
getContentPane().setBackground(Color.WHITE);
getContentPane().add(printButton, BorderLayout.NORTH);
setBounds(200, 200, 300, 300);
setVisible(true);
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception ex) {
System.out.println("Failed loading windows L&F");
System.out.println(ex);
}
}
public int getNumberOfPages()
{
return (1);
}
public PageFormat getPageFormat(int pageIndex) throws
IndexOutOfBoundsException
{
if (pageIndex < 1 && pageIndex > getNumberOfPages())
{
throw new IndexOutOfBoundsException("Page " + pageIndex +
" doesn't exist!");
}
else
{
return (defaultPageFormat);
}
}
public Printable getPrintable(int pageIndex) throws
IndexOutOfBoundsException
{
if (pageIndex < 1 && pageIndex > getNumberOfPages())
{
throw new IndexOutOfBoundsException("Page " + pageIndex +
" doesn't exist!");
}
else
{
return (this);
}
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws
PrinterException
{
if (pageIndex < 1 && pageIndex > getNumberOfPages())
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g = (Graphics2D) graphics;
double scaleX = pageFormat.getImageableWidth() / getWidth();
double scaleY = pageFormat.getImageableHeight() / getHeight();
double scale = 1;
g.translate((int) pageFormat.getImageableX(),
(int) pageFormat.getImageableY());
if (scaleX < 1 || scaleY < 1)
{
scale = scaleX < scaleY ? scaleX : scaleY;
g.scale(scale, scale);
}
printAll(g);
return Printable.PAGE_EXISTS;
}
public void startPrinting()
{
PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPageable(this);
defaultPageFormat = printerJob.defaultPage();
defaultPageFormat = printerJob.pageDialog(defaultPageFormat);
if (printerJob.printDialog())
{
try
{
printerJob.print();
}
catch (PrinterException e)
{
System.out.println(e);
}
}
}
public static void main(String[] args)
{
new PrintableFrame();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
replace the printAll line in the sample with the following to render
everything into a buffer before printing:
// The scaling is not as smooth, but it is readable.
BufferedImage buf = new BufferedImage(getWidth(),
getHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2b = buf.createGraphics();
try {
printAll(g2b);
g.drawImage(buf, 0, 0, this);
} finally {
g2b.dispose();
}
(Incident Review ID: 200826)
======================================================================