[Swing] Customisation JButton
Bonjour à tous,
je voudrais faire un bouton comme ceci :
http://img844.imageshack.us/img844/2905/testir.png
que l'ont pourrais instancier avec le path de l'image ainsi que le texte à afficher et éventuellement la couleur tu texte.
J'ai commencer à faire ceci mais sans succès : (l'image ne s'affiche pas, apparent, on a pas trop le droit de faire un setLayout sur JButton, plus rien ne s'affiche en fait)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class ApplicationButton extends JButton
{
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton button;
public ApplicationButton(String imagePath, String name)
{
this.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints(0, 0,
1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new
Insets(0, 0, 0, 0), 0, 0);
this.button = new JButton(new ImageIcon(imagePath));
this.button.setPreferredSize(new Dimension(90, 90));
this.add(this.button, constraints);
}
} |
Si vous pouviez me donner quelques pistes.
Merci d'avance
NeoKript