Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • 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
Hello!
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();
printerJob.setPrintable(ZpanelArea,pageFormat);
Paper paper = new Paper();
paper.setImageableArea(0, 0, 800, 700);
pageFormat.setPaper(paper);
if (printerJob.printDialog(aset))
{
try
{
printerJob.print(aset);
}
catch (PrinterException pe)
{
JOptionPane.showMessageDialog(this, "Ошибка при печати",
"Ошибка печати",
JOptionPane.ERROR_MESSAGE);
}
}
public int print(Graphics g, PageFormat pf, int index) throws
PrinterException
{
if (index > 0)
return NO_SUCH_PAGE;
Graphics2D g2D = (Graphics2D)g;
pf.setOrientation(pf.REVERSE_LANDSCAPE);
g2D.scale(72.0/96, 72.0/96);
print(g2D);
return Printable.PAGE_EXISTS;
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!