Bonjour a tous
Je suis entrain de développer un projet de GPAO, et je me suis arrivé à l'impression des rapports. Les rapports sont visualisés dans des JFrame.
Voici le code de la classe d'impression
J'ai rencontré deux soucis
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.print.*; public class PrintUIWindow implements Printable, ActionListener { JFrame frameToPrint; public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { /* We have only one page, and 'page' is zero-based */ return NO_SUCH_PAGE; } /* User (0,0) is typically outside the imageable area, so we must * translate by the X and Y values in the PageFormat to avoid clipping */ Graphics2D g2d = (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); /* Now print the window and its visible contents */ frameToPrint.printAll(g); /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; } public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } } public PrintUIWindow(JFrame f) { frameToPrint = f; } /* public static void main(String args[]) { UIManager.put("swing.boldMetal", Boolean.FALSE); JFrame f = new JFrame("Print UI Example"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); JTextArea text = new JTextArea(50, 20); for (int i=1;i<=50;i++) { text.append("Line " + i + "\n"); } JScrollPane pane = new JScrollPane(text); pane.setPreferredSize(new Dimension(250,200)); f.add("Center", pane); JButton printButton = new JButton("Print This Window"); printButton.addActionListener(new PrintUIWindow(f)); f.add("South", printButton); f.pack(); f.setVisible(true); }*/ }
1-Si j'imprime le JFrame, j'ai des quatre marges de 5 cm... et je veux les éviter
2- Je veux bien imprimer les JFrames sans l'entête (le title + réduire + restaurer +fermer)
Merci
Partager