我是打印一个长宽165MM长89MM的一张指..是一张车票的打印功能.....
private void printBarcode(final JBarcodeBean barcode) {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pageFormat=pj.defaultPage();
Paper paper=new Paper(); 
// paper.setSize(468,249);//设置一页纸的大小 
// paper.setImageableArea(10,10,458,239) ;//设置打印区域的大小 
pageFormat.setPaper(paper); 
pageFormat.setOrientation(PageFormat.LANDSCAPE); 
pj.setPrintable(new Printable() {
public int print(Graphics g, PageFormat format, int pageNum)
throws PrinterException {
if (pageNum > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
g2d.translate(format.getImageableX(), format.getImageableY());
double xPos, yPos;
xPos = 150;
yPos = 0;
printBarcode(g2d, barcode, xPos, yPos);
return Printable.PAGE_EXISTS;
}
}, pageFormat);
try {
pj.print();
} catch (PrinterException ex) {
JOptionPane.showMessageDialog(this, "打印失敗", titleString,
JOptionPane.ERROR_MESSAGE);
}
} private void printBarcode(Graphics2D printGraphics, JBarcodeBean barcode,
double xPos, double yPos) {
Color oldBackground = barcode.getBackground();
barcode.setBackground(barcode.getBarcodeBackground());
printGraphics.translate(xPos, yPos);
barcode.paint(printGraphics);
printGraphics.translate(-xPos, -yPos);
printGraphics.drawString("kkkkkkk----------213123",150,100);
barcode.setBackground(oldBackground);
}
这个是我的代码。..不知道为什么我在设置paper.setSize(468,249);//设置一页纸的大小的时候无效``````他打印的时候如果坐标设置大一点他就会只有打印一半```
而且我的打印是在APPLET上面实现的````有人知道为什么吗