• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with setting attributes to printDialog window... Please advise...  RSS feed

Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am adding �Print� functionality to my application and have problem with printDialog window.
When printer window opens it contains left and right margins set to defaults but I need it to have left and right margins set with data from my application. Is it possible to do with Printable?
I am printing JLabel�
In the below code if I pass HashPrintRequestAttributeSet to print() method it won�t print at all. How to solve this problem?
Here is my code:
HashPrintRequestAttributeSet aset=new HashPrintRequestAttributeSet();
aset.add(new JobName("Printing",null));
aset.add(new MediaPrintableArea(2, 10, 50, 50,MediaPrintableArea.MM));
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat =printerJob.defaultPage();
Paper paper = new Paper();
paper.setImageableArea(0, 0, 800, 700);
if (printerJob.printDialog(aset))
catch (PrinterException pe)
JOptionPane.showMessageDialog(this, "Ошибка при печати",
"Ошибка печати",
public int print(Graphics g, PageFormat pf, int index) throws
if (index > 0)
return NO_SUCH_PAGE;
Graphics2D g2D = (Graphics2D)g;
g2D.scale(72.0/96, 72.0/96);
return Printable.PAGE_EXISTS;
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!