// here are my example for jframe, you need to import the following
import java.applet.*; // for applet
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mycom extends JFrame implements ActionListener
{
String nameList[] = {"Adam","Bob"};
JComboBox selectName;
JCheckBox checkName[];
public mycom()
{
super("JComboBox and checkbox");
selectName = new JComboBox(nameList);
checkName = new JCheckBox[20];
getContentPane().setLayout(new GridLayout(21,1));
getContentPane().add(selectName);
selectName.addActionListener(this);
for (int i=0;i<nameList.length;i++)
{
checkName = new JCheckBox(nameList);
getContentPane().add(checkName);
}
}
public void actionPerformed(ActionEvent e)
{
System.out.println(selectName.getSelectedIndex());
if (selectName.getSelectedIndex()!=-1)
{
for (int i=0;i<nameList.length;i++)
{
checkName.setSelected(false);
}
checkName[selectName.getSelectedIndex()].setSelected(true);
}
}
public static void main(String args[])
{
mycom mycomObj = new mycom();
mycomObj.setSize(400,400);
mycomObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mycomObj.setVisible(true);
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.