import javax.swing.*; import java.awt.event.*; public class Valik1 extends JPanel implements ItemListener, ActionListener{ JComboBox valik=new JComboBox(); JTextField tf=new JTextField(15); public Valik1(){ valik.addItem("Juku"); valik.addItem("Kati"); valik.addItem("Mati"); add(valik); add(tf); valik.addItemListener(this); valik.addActionListener(this); valik.setEditable(true); } public void actionPerformed(ActionEvent e){ if(e.getSource()==valik && valik.getSelectedIndex()==-1){ valik.addItem(valik.getSelectedItem()); } } public void itemStateChanged(ItemEvent e){ tf.setText(valik.getSelectedItem().toString()+" "+ valik.getSelectedIndex()); } public static void main(String[] arg){ JFrame f=new JFrame("Rippmenüü"); f.add(new Valik1()); f.setSize(200, 200); f.setVisible(true); } }