Salut a tous ,
Donc voila mon problème je suis en train de dessiner dans un JPanel mais quand je réduit l'application tous les dessins sont parties.
j'ai cherché partout mais pas de solution!
voici mon code :

PaintComponent(g) :

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
public class GraphicWorld extends JPanel
    {
 
     @Override
   public void paintComponent (Graphics g)
      {
 
 
 
       super.paintComponent(g);
       Graphics2D gfx = (Graphics2D)g;
 
       System.out.println(valuesId[0]);    
      if (!"0".equals(valuesId[0]))
      {
 
       if(valuesId[0].contains("Port number"))
        {
 
         gfx.drawString("(Port)", 30, 20);
         gfx.drawString(valuesId[1],30, 140);
        }
       if(valuesId[0].contains("Port Extension"))
        {
            gfx.drawString("(EXT)", 100, 20);
            gfx.drawString("("+valuesId[1]+" )", 100, 140);
          //  draw(g);
        }
       if(valuesId[0].contains("Forward Extension"))
        {
 
          //  draw(g);
        }
       if(valuesId[0].contains("Port Activity"))
        {
          if(valuesId[1].contains("ON-HOOK"))
          {
 
           gfx.drawImage(imgOnhook,87, 70, null);
           gfx.dispose();
          }
          if(valuesId[1].contains("OFF-HOOK"))
          {
           gfx.drawImage(imgOffhook, 87, 70, null);
           }
        }
       if (valuesId[0].contains("Forward Staus"))
       {
           System.out.println("paaassss ");
           gfx.drawString("(FW)", 236, 20);
       }
       if(valuesId[0].contains("Forward Extension"))
        {
 
                gfx.drawLine(135,87,235,87);
                gfx.drawLine(230, 91, 235, 87);
                gfx.drawLine(230,83,235,87);
 
                gfx.drawOval(135,84,6,6);
                gfx.setColor(Color.BLACK);
                gfx.fillOval(135, 84, 6, 6);
 
            if(valuesId[1].contains("NONE"))
            {
               gfx.drawString("(NF)", 236 , 87);
 
            }
            else
            {
 
               gfx.drawImage(imgOnhook,236,70, null);
 
 
            }
        }
       if(valuesId[0].contains("Dialing"))
        {
            gfx.drawString("("+ valuesId[1]+" )", 100, 180);
            //draw(g);
        }
 
 
      }
    }
 
}


DocumentListener() :
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
protected class MyDocumentListener implements javax.swing.event.DocumentListener {
 
 
 
        @Override
   public void changedUpdate(javax.swing.event.DocumentEvent e) {
            // text has been altered in the textarea
 
            }
        @Override
   public void insertUpdate(javax.swing.event.DocumentEvent e) 
        {
                // text has been added to the textarea 
 
            try { 
               //if not prompt Line
                if (!Traffic.getText(Traffic.getLineStartOffset(Traffic.getLineCount()-1),
                  Traffic.getLineEndOffset(Traffic.getLineCount()-1)-Traffic.getLineStartOffset(Traffic.getLineCount()-1)).contains(">>"))
                     {//if a line after a replace has been inserted
 
                     if (Traffic.getLineCount()  == (lastreplace + 2) ) 
              {
                       System.err.println(Traffic.getText(Traffic.getLineStartOffset(lastreplace),
                                                             Traffic.getLineEndOffset(lastreplace) - 
                                                                Traffic.getLineStartOffset(lastreplace)));
                 //  PortArchitecture (Traffic.getText(Traffic.getLineStartOffset(lastreplace),
                      //          Traffic.getLineEndOffset(lastreplace) - 
                       //                 Traffic.getLineStartOffset(lastreplace)));
 
 
                  String line = Traffic.getText(Traffic.getLineStartOffset(lastreplace),Traffic.getLineEndOffset(lastreplace) -  Traffic.getLineStartOffset(lastreplace));
 
                   //repaint only with a valid line
                   if (line.indexOf(":") != (-1)) 
                   {
                      valuesId[0] = line.substring(0,line.indexOf(":"));
                      valuesId[1] = line.substring(line.indexOf(":")+1);
 
                      i+=1;
                      System.out.println(" i =  " + i + " :  "+ valuesId[0]);
 
                      if (i==2)
                      {
 
                          graphicPanel.repaint(30,10,100,180);//Port Number
 
                      }
                      if(i==4)
                      {
                          graphicPanel.repaint(90,10,80,180);//Port Extension 
                      }
 
                      if (i==5)
                      {
                          graphicPanel.repaint(87,70,50,35);//Port Activity
                      }
                      if (i==6)
                      {
                          graphicPanel.repaint(236,10,25,20);//(FW)
                      }
                      if (i==7)
                      {
                          graphicPanel.repaint(135,75,130,24);//FW EXT
 
                      }
 
                   } 
                   lastreplace +=1;
              }
 
                else//last line when it's not detected by the previous condition it'll be consumed here
              {
                            //                     LAST       LINE
              }
          }
            Traffic.setCaretPosition(Traffic.getDocument().getLength());
 
 
            } catch (BadLocationException ex) {
                Logger.getLogger(TrafficSerialPort.class.getName()).log(Level.SEVERE, null, ex);
            }
 
        }
 
        @Override
   public void removeUpdate(javax.swing.event.DocumentEvent e) {
      // text has been removed from the textarea
 
      }
 
    }