JComboBox / boite de dialogue

nergaahl Messages postés 11 Date d'inscription mardi 9 septembre 2003 Statut Membre Dernière intervention 16 avril 2008 - 11 juin 2007 à 14:48
amundain Messages postés 110 Date d'inscription mercredi 28 mars 2007 Statut Membre Dernière intervention 28 août 2012 - 11 juin 2007 à 16:12
<!-- / icon and title -->
<!-- message -->Bonjour,


J'aimerai savoir comment intégrer une JComboBox lorsque je fais un
JOptionPane.showInputDialog au lieu de rentrer manuellement ou de créer
moi même une boite de dialogue.


merci !!

1 réponse

amundain Messages postés 110 Date d'inscription mercredi 28 mars 2007 Statut Membre Dernière intervention 28 août 2012 1
11 juin 2007 à 16:12
Salut,

Il y a moyen, effectivement, en utilisant la méthode constructeur de ton InputDialog :

showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)

ou le tableau d'Object correspond aux valeurs que tu veux mettres dans ta JComboBox.

ex : String[] toto=new String[] {"1","2"};

-----------> quand tu ajoutes "toto" au constructeur en tant que Object[] selectionValues, tu obtiens une ComboBox avec "1" et "2".

A +,

amundain

Je te mets un petit code vite fait :

import javax.swing.*;


public class Main2 extends JFrame{

private String[] toto=new String[]{"1","2"};

public Main2()
{
JOptionPane.showInputDialog(this, "voilà une JCOmboBoix", "JComboBox dans un InputDialog", 2, new ImageIcon("Alert.png"), toto, "1");
}
public static void main(String[] args) {
Main2 T=new Main2();
}
}
0
Rejoignez-nous