Bonjour à tous,
Je galère avec une notion pourtant toute simple, un JPanel à l'intérieur d'une JFrame avec surcharge de leur méthode paint respective. J'obtiens en fait un pb, même si l'ordre des paint est correct, le JPanel inclu est masqué par un fillRect dans la JFrame qui inclut le JPanel !
Voici le code de la JFrame avec le JPanel principal :
et le JPanel inclu :
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 package tests; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import javax.swing.JFrame; public class MainFrame extends JFrame { public MainFrame() { super( "tests" ); init(); } private void init() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setUndecorated(true); Container pane = getContentPane(); pane.setLayout( new BorderLayout() ); PanelInside panelInside = new PanelInside(); pane.add( panelInside ); setBounds(50, 50, 800, 600); setVisible(true); } public void paint(Graphics g) { System.out.println( "painting MainFrame" ); super.paint(g); g.setColor( Color.GREEN ); g.fillRect(10, 10, getWidth()-20, getHeight()-20); g.setColor( Color.RED ); g.drawRect(10, 10, getWidth()-20, getHeight()-20); } public static void main(String[] args) { new MainFrame(); } }
Le drawRect bleu de PanelInside.paint() est masqué par le fillRect vert de MainFrame.paint(). Pourtant les logs donnent :
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 package tests; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; public class PanelInside extends JPanel { public PanelInside() { super( new BorderLayout() ); } public void paint(Graphics g) { System.out.println( "painting PanelInside" ); super.paint(g); g.setColor( Color.BLUE ); g.drawRect(50, 50, getWidth()-100, getHeight()-100); } }
painting MainFrame
painting PanelInside
!!!
Cela fait un moment que je cherche et là, franchement, je coince ! Toute aide sera la bienvenue en vous remerciant par avance.
Et, bon week-end à tous
-David-
Partager