-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
x86
-
windows_nt
Name: gsC80088 Date: 02/11/99
sun.java2d.PathGraphics.drawString can't handle no label checkbox, empty list item, empty textfield, etc.
The following is the sample code (modified from ComponentPrinterFrame.java in Monica Pawlan's
article "Java2D: New Printing Package")
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
public class ComponentPrinterFrame
extends JFrame
implements Printable {
public static void main(String[] args) {
ComponentPrinterFrame cpf = new ComponentPrinterFrame();
cpf.setVisible(true);
}
public ComponentPrinterFrame() {
super("ComponentPrinterFrame v1.0");
createUI();
}
protected void createUI() {
JPanel panel = new JPanel();
JButton printButton = new JButton("Print");
panel.add(printButton);
panel.add(new JList(new Object[] { "One", "Two", "Three" }));
panel.add(new JButton("Push me"));
panel.add(new JCheckBox("Chess", true));
panel.add(new JCheckBox());
panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
panel.setDoubleBuffered(false);
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(ComponentPrinterFrame.this);
if (pj.printDialog()) {
try { pj.print(); }
catch (PrinterException pe) {
System.out.println(pe);
}
}
}
});
setContentPane(panel);
setSize(400, 400);
// Center.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
int x = (screenSize.width - frameSize.width) / 2;
int y = (screenSize.height - frameSize.height) / 2;
setLocation(x, y);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.translate(pf.getImageableX(), pf.getImageableY());
getContentPane().print(g2);
return PAGE_EXISTS;
}
}
(Review ID: 47744)
======================================================================
Name: gsC80088 Date: 03/12/99
I have an applet running in jdk1.2 plugin. The applet
has some table which the user can print. (BTW, the same
behavior occurs when I run as an application)
I can not include my source code, but the problem should
be easy enough to duplicate.
The problem occurs when I try to print a JTable,
and some if its values are null, or empty strings.
So for example, in my TableModel the getValueAt(row, col)
sometime returns null or "". When I try to print that
table the call table.paint(graphics) throws the IllegalArgumentException exception. (see trace below)
What actually gets printed is all the fields before the
null field. So for example if I have 5 rows and the fouth
column of every row is null, then only the first 3 columns
of the first row will be printed. The rest of the rows
will not even be printed.
java.lang.IllegalArgumentException: Zero length string passed to TextLayout cons
tructor.
at java.awt.font.TextLayout.<init>(TextLayout.java:337)
at sun.java2d.PathGraphics.drawString(PathGraphics.java:426)
at javax.swing.plaf.basic.BasicGraphicsUtils.drawString(Compiled Code)
at javax.swing.plaf.basic.BasicLabelUI.paintEnabledText(Compiled Code)
at javax.swing.plaf.basic.BasicLabelUI.paint(Compiled Code)
at javax.swing.plaf.ComponentUI.update(Compiled Code)
at javax.swing.JComponent.paintComponent(Compiled Code)
at javax.swing.JComponent.paint(Compiled Code)
at javax.swing.CellRendererPane.paintComponent(Compiled Code)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Compiled Code)
at javax.swing.plaf.basic.BasicTableUI.paintRow(Compiled Code)
at javax.swing.plaf.basic.BasicTableUI.paint(Compiled Code)
at javax.swing.plaf.ComponentUI.update(Compiled Code)
at javax.swing.JComponent.paintComponent(Compiled Code)
at javax.swing.JComponent.paint(Compiled Code)
at com.randomwalk.knightsecurities.eknight.client.TablePrinter.print(Com
piled Code)
at sun.java2d.RasterPrinterJob.printPage(RasterPrinterJob.java:504)
at sun.java2d.RasterPrinterJob.print(RasterPrinterJob.java:235)
at com.randomwalk.knightsecurities.eknight.client.TablePrinter$PrintThre
ad.run(TablePrinter.java:39)
Version of Java - java full version "JDK-1.2-V"
======================================================================
- duplicates
-
JDK-4223328 PeekGraphics.drawString differs fatally from basic Graphics2D
-
- Resolved
-