Hi.. I have a problem with Label printing. We use Dymo LabelWriter (Turbo 330) to print labels.
Below is the sample code I used. [b]This piece of code works well when I used the java version j2sdk1.4.2_10[/b] [b]But when I used jdk1.5.0_14, there is a blank print.[/b] [b]With jdk1.5.0_14, when I selected the printer option as Adobe PDF, Its working fine. But,I am facing problem when Dymo LabelWriter is selected as printer[/b]. Please help me to solve this. import java.util.Vector; import java.awt.print.*; import java.awt.*; import javax.swing.JPanel; public class DymoLabelPrinting{ public static void main(String args[]) { Vector vLabels = new Vector(); vLabels.add("Mr.TIGERWOODS"); vLabels.add("H NO 2-7, AMEERPET"); vLabels.add("HYDERABAD"); vLabels.add("ANDHRA PRADESH,INDIA"); PrintLabels printLabels = new PrintLabels(vLabels); printLabels.prepareLabels(); Thread labelPrintingThread=new Thread(printLabels); labelPrintingThread.start(); } } //------------------------------------------- class PrintLabels implements Runnable { Vector records; String strOrientation; PageFormat pageFormat; PrinterJob printJob; Page page ; public PrintLabels(Vector vector) { pageFormat = null; printJob = null; strOrientation = "Landscape"; records = vector; } public void run() { print(); } public void prepareLabels() { page = new Page(); page.addLabel(records); } public void print() { printJob = PrinterJob.getPrinterJob(); try { Paper paper = new Paper(); paper.setSize(165, 288); paper.setImageableArea(7, 0, 165, 288); pageFormat = printJob.defaultPage(); pageFormat.setPaper(paper); if(strOrientation.equals("Portrait")) pageFormat.setOrientation(pageFormat.PORTRAIT); else pageFormat.setOrientation(pageFormat.LANDSCAPE); printJob.setPrintable(page, pageFormat); if(printJob.printDialog()==false) return; printJob.print(); }catch(PrinterException e){ e.printStackTrace(); } } } //---------------------------- class Page extends JPanel implements Printable { private int nLeftMargin; private int nTopMargin; private int nVerticalSpace; private int nHorizantalSpace; private int nMaxLabelsPerRow; private int nMaxLabelsPerCol; private int nlabelHeight; private int nLabelWidth; private String strLabelOreintation; int nPixels; private Vector vecLables; private String strOreintation; public Page() { nPixels = 15; nLeftMargin = 7; nTopMargin = 0; nVerticalSpace = 0; nHorizantalSpace = 0; strOreintation = "Landscape"; nMaxLabelsPerRow = 1; nMaxLabelsPerCol = 1; nlabelHeight = 72; nLabelWidth = 189; strLabelOreintation="Landscape"; vecLables = new Vector(); setBackground(Color.white); } public boolean addLabel(Vector vector) { if(strOreintation.equals("Portrait") || strOreintation.equals("Landscape")) { vecLables.add(vector); } return true; } void drawPage(Graphics2D graphics2d) { Graphics2D graphics2d1 = graphics2d; graphics2d1.setBackground(Color.white); graphics2d1.clearRect(0, 0, nLabelWidth, nlabelHeight); graphics2d1.setColor(Color.black); int nLeftmargin1 = nLeftMargin; int nTopMargin1 = nTopMargin; int nMaxLablesPerRow1 = nMaxLabelsPerRow; int nMaxLablesPerColumn1 = nMaxLabelsPerCol; for(int i1 = 0; i1 < vecLables.size(); i1++) { drawLabel(graphics2d1, (Vector)vecLables.elementAt(i1), nLeftmargin1, nTopMargin1, false); if(!strOreintation.equals("Portrait") && !strOreintation.equals("Landscape")) continue; nLeftmargin1 = nLeftmargin1 + nLabelWidth + nHorizantalSpace; if(nMaxLablesPerRow1 <= 0 || --nMaxLablesPerRow1 != 0) continue; if(--nMaxLablesPerColumn1 == 0) return; nMaxLablesPerRow1 = nMaxLabelsPerRow; nLeftmargin1 = nLeftMargin; nTopMargin1 = nTopMargin1 + nlabelHeight + nVerticalSpace; } } public void drawLabel(Graphics2D graphics2d, Vector vecLables, int nLeftmargin1, int nTopMargin1, boolean flag) { String strFontName = "Ariel"; String strFontSize = "9"; if(strFontName == null) strFontName = "Ariel"; if(strFontSize == null) strFontSize = "10"; int nFontSize = Integer.parseInt(strFontSize); Font font = new Font(strFontName, 0, nFontSize); graphics2d.setClip(nLeftmargin1, nTopMargin1, nLabelWidth, nlabelHeight); if(flag) graphics2d.drawRect(nLeftmargin1, nTopMargin1, nLabelWidth - 3, nlabelHeight - 3); graphics2d.setFont(font); FontMetrics fontmetrics = graphics2d.getFontMetrics(font); int nHeight = fontmetrics.getHeight(); nLeftmargin1 += 4; nTopMargin1 += 20; for(int nIndex = 0; nIndex < vecLables.size(); nIndex++) { String strDataToPrint = (String)vecLables.elementAt(nIndex); if(strLabelOreintation.equals("Landscape") || strLabelOreintation.equals("Portrait")) { graphics2d.drawString(strDataToPrint, nLeftmargin1, nTopMargin1); nTopMargin1 += nHeight; continue; } } System.out.println("java version=====>"+System.getProperty("java.version")); } public int print(Graphics g, PageFormat pageformat, int i) throws PrinterException { int nWidth = (int)pageformat.getWidth(); int nHeight = (int)pageformat.getHeight(); Graphics2D graphics2d = (Graphics2D)g; graphics2d.setClip(0, 0, nWidth, nHeight); drawPage(graphics2d); int l = 1; return i < l ? 0 : 1; } } Thanks, Chakri. [Message sent by forum member 'chakrivemuri' (chakrivemuri)] http://forums.java.net/jive/thread.jspa?messageID=275717 =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".