Je cherche mais je ne comprends pas // bouton image

olidemo Messages postés 3 Date d'inscription mardi 29 avril 2003 Statut Membre Dernière intervention 14 décembre 2009 - 18 nov. 2009 à 14:47
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 - 18 nov. 2009 à 14:57
Voilà mon problème est simple. Je veux faire un bouton avec une image, mais rien à faire.. L'appli semble bien chargée l'image, mais celle-ci ne s'affiche pas. Voilà ce qui est je pense intéressant dans mon code :

Dimension btn=new Dimension(100,100);
Mesboutons agent=new Mesboutons("btn/btn_agent.gif",100,100);

panel.add(agent,new GBC(0,1).setAnchor(GBC.CENTER).setWeight(0,0).setInsets(10));

puis :

import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
/**
*
* @author Olivier
*/

public class Mesboutons extends JPanel {

public Mesboutons(String url, int x, int y){
try{
ImageIcon icon=new ImageIcon(url);
JButton jb=new JButton(icon);
jb.setSize(x, y);
} catch (Exception exc){
System.out.println("Can't create because of "+exc);
}
}

}


ALors je suis nul je sais, mais je veux comprendre...

[B)]olidemo

1 réponse

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
18 nov. 2009 à 14:57
Salut,

Tu n'ajoute jamais ton bouton à ton JPanel...
public Mesboutons(String url, int x, int y){
try{
ImageIcon icon=new ImageIcon(url);
JButton jb=new JButton(icon);
jb.setSize(x, y);
add(jb); // AJOUT DU JBUTTON DANS LE JPANEL
} catch (Exception exc){
System.out.println("Can't create because of "+exc);
}
} 

______________________________________
DarK Sidious
0
Rejoignez-nous