import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Valik2 extends JPanel implements ItemListener{ JComboBox valik=new JComboBox(); JTextField tf=new JTextField(15); public Valik2(){ valik.addItem(3); valik.addItem(50); valik.addItem(90); setLayout(new BorderLayout()); add(valik, BorderLayout.NORTH); add(tf, BorderLayout.SOUTH); valik.addItemListener(this); valik.setEditable(true); valik.setEditor(new ValikuRedaktor()); } 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 Valik2()); f.setSize(200, 200); f.setVisible(true); } }