Bonjour,
Je possede une application (donc une fenêtre principale) composé de plusieurs composants de classe A (étendant JPanel).
Je veux pouvoir ouvrir une JDialog par desus qui contient dans un de ces panel l'image d'un des composants A.

Pour cela j'ai mis une méthode qui renvoie l'image de mon composant dans ma classe A :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
public Image getImage() { 
    int width = getWidth(); 
    int height = getHeight(); 
    BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); 
    Graphics2D g = image.createGraphics(); 
    paintAll(g); 
    g.dispose(); 
    Image image2 = Toolkit.getDefaultToolkit().createImage(image.getSource()); 
    return image2; 
  }
Ensuite j'ajoute cette image au panel de ma JDialog :
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
private JPanel getGraphPanel() { 
    if (graphPanel == null) { 
      graphPanel = new JPanel(); 
      graphPanel.setFont(ParameterUI.PAC7000_FONT); 
      graphPanel.setLayout(new GridBagLayout()); 
      GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); 
      gridBagConstraints6.fill = java.awt.GridBagConstraints.BOTH; 
      gridBagConstraints6.weightx = 1.0; 
      gridBagConstraints6.weighty = 1.0; 
      graph.setRectangle(graphPanel.getBounds()); 
    graphImage = new GraphImage(graph.getImage()); 
      graphPanel.add(graphImage, gridBagConstraints6); 
      graphPanel.setPreferredSize(new Dimension(210, 250)); 
    } 
    return graphPanel; 
  }
et graphImage étant mon panel affichant l'image :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
  private class GraphImage extends JPanel {
 
    private Image image;
    public GraphImage(Image image) {
      this.image = image;
    }
 
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D graphics2D = (Graphics2D) g;
      graphics2D.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null),null);
    }
  }
Malheurseusement rien ne s'affiche, je vois juste les bord du panel de la JDialog, pourtant l'image possede une hauteur et une longueur qui semble cohérent.
Si quelqu'un voit d'où vien l'erreur, cela pourrait m'aider, merci d'avance.