
{filelink=23}
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
public class JComboBoxUpdate extends JFrame
{
JComboBox myCmb;
public JComboBoxUpdate()
{
JPanel mainPanel=new JPanel();
myCmb=new JComboBox();
JButton btnSupprimer=new JButton("Modifier");
btnSupprimer.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
DefaultComboBoxModel cmbModel=(DefaultComboBoxModel)myCmb.getModel();
// Modifier l'élément sélectionné
cmbModel.setSelectedItem("=>#");
}
}
);
Object jours[]={"Lundi", "Mardi", "Mercredi"
, "Jeudi", "Vendredi", "Samedi"};
for(Object elem:jours)
{
myCmb.addItem(elem);
}
mainPanel.add(myCmb);
mainPanel.add(btnSupprimer);
add(mainPanel);
}
public static void main (String[] args)
{
JComboBoxUpdate frame=new JComboBoxUpdate();
frame.setTitle("Exemple de Modification dans JComboBox");
frame.setSize(200, 100);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}