Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package whatever; // don't place package name! */
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Exemplo extends JFrame
- {
- private String t;
- public Exemplo()
- {
- setTitle("Exemplo combo");
- setSize(500, 500);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocationRelativeTo(null);
- JPanel jp = new JPanel();
- jp.setLayout(null);
- add(jp);
- JComboBox combo = new JComboBox();
- combo.addItem("Opção 1");
- combo.addItem("Opção 2");
- combo.addItemListener(new ItemListener(){
- @Override
- public void itemStateChanged(ItemEvent event) {
- if (event.getStateChange() == ItemEvent.SELECTED) {
- String value = event.getItem().toString();
- // faz algo conforme a opção selecionada
- if (value.equals("Opção 1")) {
- // faz algo se selecionou a opção 1
- }
- }
- }
- });
- jp.add(combo);
- combo.setBounds(180, 200, 125, 30);
- }
- public static void main(String[] args)
- {
- Exemplo ex = new Exemplo();
- ex.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement