Combo box in Java Program
Combo box in Java Program
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class comboBox
{
public Static void main(String args[])
{
JFrame frame=new JFrame();
Container cp=frame.getContentPane();
JPanel panel=new JPanel();
final JLabel lab=new JLabel("sample.Text");
panel.add(lab);
final JComboBox combo=new JComboBox();
combo.addItem("Zero");
combo.addItem("First");
combo.addItem("second");
combo.setEditable(true);
System.out.println("Items="+combo.getItemcount());
combo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e);
{
System.out.println("selected index="+combo.getSelectedIndex()+"selected item="+combo.getSelectedItem());
}
});
panel.add(combo);
cp.add(panel);
frame.setSize(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
0 coment�rios:
Post a Comment