Bonjour à tous,
Je suis en phase de finalisation d'une application java (Eclipse 3.2 + J2SE 1.5) de gestion de ressource. Dans cette application, j'affiche un emploi de temps sous forme de JTable relooké et j'y matérialise les tâches par des rectangle transparents au-dessus des cellules du JTable.¨Pour cela, je redéfinit la méthode paintComponent(Graphics g) du JTable et j'utilise à l'interieur un graphics2D pour la transparence
Le problème maintenant est que je voudrais imprimer cet JTable avec le code
Code : 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 public void paintComponent(Graphics g){ super.paintComponents(g); int width = getWidth(); int height = getHeight(); Graphics2D g2d = (Graphics2D)g; // Ligne d'erreur Paint old = g2d.getPaint(); // Sauvegarde de l'anien mode de peinture // Création du gradient de peinture GradientPaint gp = new GradientPaint(0, 0, color, width, height, color.brighter().brighter()); g2d.setPaint(gp); g2d.fillRect(0, 0, width, height); if(_ishour){ g2d.setPaint(ShinColor.getDefaultOrange()); g2d.setStroke(new BasicStroke(2)); g2d.drawLine(0, 1, width, 1); g2d.drawLine(0, 0, 0, height); } else if(_isquart){ g2d.setPaint(ShinColor.getDefaultOrange()); g2d.setStroke(new BasicStroke(2)); g2d.drawLine(0, height/2, width, height/2); g2d.drawLine(0, 0, 0, height); } else if(_ishalph){ g2d.setPaint(ShinColor.getDefaultOrange()); g2d.setStroke(new BasicStroke(2)); g2d.drawLine(0, height, width, height); g2d.drawLine(0, 0, 0, height); } if(_hour != null){ // Update des positions des composants _hour.setBounds(new Rectangle(0, 0, this.getWidth(), 4 * this.getHeight()/5)); } // Restauration de l'ancien mode de peinture g2d.setPaint(old); }
et j'ai une exception
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Properties props = new Properties(); props.put("awt.print.paperSize", "a4"); props.put("awt.print.destination", "printer"); PrintJob pJob = getToolkit().getPrintJob(this, "Printing_Test", props); if (pJob != null) { Graphics pg = pJob.getGraphics(); MonJTable.printAll(pg) pg.dispose(); pJob.end(); }
qui se rapporte à la ligne dans laquelle je caste le graphics en graphics2D
Code : 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 java.lang.ClassCastException: sun.print.ProxyPrintGraphics at clientInterfacePackage.shinGoodies.ShinJTableHour.paintComponent(ShinJTableHour.java:75) at javax.swing.JComponent.printComponent(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.CellRendererPane.paintComponent(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source) at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source) at javax.swing.plaf.ComponentUI.update(Unknown Source) at javax.swing.JComponent.paintComponent(Unknown Source) at clientInterfacePackage.shinGoodies.ShinJTable.paintComponent(ShinJTable.java:302) at javax.swing.JComponent.printComponent(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JViewport.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JLayeredPane.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.printChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.print(Unknown Source) at java.awt.GraphicsCallback$PrintCallback.run(Unknown Source) at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source) at sun.awt.SunGraphicsCallback.runComponents(Unknown Source) at java.awt.Container.print(Unknown Source) at sun.awt.windows.WComponentPeer.print(Unknown Source) at sun.awt.windows.WCanvasPeer.print(Unknown Source) at sun.awt.windows.WPanelPeer.print(Unknown Source) at java.awt.GraphicsCallback$PeerPrintCallback.run(Unknown Source) at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source) at java.awt.Component.printAll(Unknown Source) at clientInterfacePackage.MainFrame.actionPerformed(MainFrame.java:660) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.AbstractButton.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Je ne sais pas quoi faire!
Partager