Bonjour,

j'ai envoyer beaucoup de message a propos de l'insertion d'une image dans une Jframe. J'y suis arrive , la deuxieme etape c'est inserer une Jlist par exemple dans une image.
Avec applet cela se fait tres facilement.
En revanche Jframe pose des barrieres importantes a cette insertion.

J'ai creer une classe Jpanel pour inserer une image dans un Jframe :

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
// Updates: 2004.07.16
 
 
import java.awt.*;
import javax.swing.*;
 
 
/**
 * Displays a centered image in the available area. If the picture is too big
 * (width or height), a zoom will be applied in order to show the full image.
 * This class works also if the picture is in a jar file.
 * @author Michel Deriaz 
 */
public class Picture extends JPanel {
  private Image img;      
 
 
  /**
   * Loads the specified image, which must be a JPG, a GIF, or a PNG.
   * @param file the file to load
   */  
  public Picture(String file) {
    img = new ImageIcon(getClass().getResource(file)).getImage();
    repaint(); 
  }
 
 
  public void paintComponent(Graphics g) {
 
	super.paintComponent(g); 
	Graphics2D g2D=(Graphics2D )g;
	Graphics2D g2d = (Graphics2D)this.img.getGraphics();
 
  }
}

J'ai tente de mixer une Jlist avec une image mais rien n'y fait :
L'imgae n'est meme pas afficher pourtant la classe picture est correct car recupere dans le faq . Quelau'un peu il m'aider de ce cote la ?
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
 
 public class JListExample extends JFrame implements ListSelectionListener
  {	
	JList myJList;
 private Picture pic;
 
	public JListExample()
	{
		super("JList Example");
	/*Load an image */
	Picture pic = new Picture("portable.JPG");
 
		String[] data = {"Boite de reception","Envoyer Message","Envoyer Image"};
 
		JPanel j = new JPanel();
 		myJList = new JList(data);
		myJList.addListSelectionListener(this);
 
		j.add(this.myJList);
		//JScrollPane p = new JScrollPane(this.myJList,
			//JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
			//JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 
		//this.getContentPane().add( j); 	
 
		this.myJList.setSelectedIndex(1);
		this.myJList.setValueIsAdjusting(true);
		this.pack(); 
		this.show();	 
	}