U
Ulrich Eckhardt
Hi,
i have written a small testprogramm for printing. This testprogramm
should print out the halve page in green. On windows this programm
works as expected but on linux (OpenSuse 10.1 JDK 1.4.2-12 and 1.5.0-7)
i get only a blank page. Even if i redirect the printer output into
a file and view it with ghostscript the page is empty. Has
anybody an idea whats going wrong ?
public class testFrame extends JFrame implements Printable {
private JButton jButton = null;
private PrinterJob printJob = null;
/**
* This method initializes
*
*/
public testFrame() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setSize(new Dimension(173, 123));
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Test");
this.setVisible(true);
this.setContentPane(getJButton());
printJob = PrinterJob.getPrinterJob();
//Book bk = new Book();
//bk.append(this, printJob.defaultPage());
// Pass the book to the PrinterJob
// printJob.setPageable(bk);
printJob.setPrintable(this);
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Print");
jButton.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent e) {
System.out.println ("Print");
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
}
dispose();
}
}
});
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
testFrame mW = new testFrame();
System.out.println("Starting");
mW.initialize ();
}
public int print (Graphics g, PageFormat pf, int pi) throws
PrinterException {
if (pi > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.green);
g2.setBackground(Color.gray);
g2.scale (1/72,1/27);
g2.fillRect ((int)pf.getImageableX(),
(int)pf.getImageableY(),
(int)pf.getImageableWidth(),
(int)pf.getImageableHeight() / 2);
return Printable.PAGE_EXISTS;
}
}
Thanks for any help
Uli
i have written a small testprogramm for printing. This testprogramm
should print out the halve page in green. On windows this programm
works as expected but on linux (OpenSuse 10.1 JDK 1.4.2-12 and 1.5.0-7)
i get only a blank page. Even if i redirect the printer output into
a file and view it with ghostscript the page is empty. Has
anybody an idea whats going wrong ?
public class testFrame extends JFrame implements Printable {
private JButton jButton = null;
private PrinterJob printJob = null;
/**
* This method initializes
*
*/
public testFrame() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setSize(new Dimension(173, 123));
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle("Test");
this.setVisible(true);
this.setContentPane(getJButton());
printJob = PrinterJob.getPrinterJob();
//Book bk = new Book();
//bk.append(this, printJob.defaultPage());
// Pass the book to the PrinterJob
// printJob.setPageable(bk);
printJob.setPrintable(this);
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Print");
jButton.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent e) {
System.out.println ("Print");
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
}
dispose();
}
}
});
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
testFrame mW = new testFrame();
System.out.println("Starting");
mW.initialize ();
}
public int print (Graphics g, PageFormat pf, int pi) throws
PrinterException {
if (pi > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.green);
g2.setBackground(Color.gray);
g2.scale (1/72,1/27);
g2.fillRect ((int)pf.getImageableX(),
(int)pf.getImageableY(),
(int)pf.getImageableWidth(),
(int)pf.getImageableHeight() / 2);
return Printable.PAGE_EXISTS;
}
}
Thanks for any help
Uli