Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created June 14, 2022 07:30
Show Gist options
  • Save uncoded-ro/f644d0ad51c1c12cf3b57072dd4ab988 to your computer and use it in GitHub Desktop.
Save uncoded-ro/f644d0ad51c1c12cf3b57072dd4ab988 to your computer and use it in GitHub Desktop.
package ro.virtualcampus.gui;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ComboBoxPanel extends JPanel implements ItemListener {
private static final long serialVersionUID = 1L;
private JComboBox list;
private JLabel text1, text2;
public ComboBoxPanel() {
setLayout(new GridLayout(3, 1));
text1 = new JLabel("Selecteaza echipa favorita !");
String[] listModel = { "Universitatea Craiova", "Poli Timisoara", "Steaua Bucuresti" };
list = new JComboBox(listModel);
list.setSelectedIndex(1);
text2 = new JLabel("");
add(text1);
add(list);
add(text2);
list.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
Object choice = list.getSelectedItem();
text2.setText(choice.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment