: Hi all,
:
[quoted text clipped - 18 lines]
: });
: ---
Here's something to play around with
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame implements ItemListener
{
JComboBox aList, bList;
String[] aText = {"Britain","France","Italy","USA"};
String[][] bText = {{"Liverpool","London","Manchester"},{"Calais","Lyons","Paris"},
{"Florence","Rome","Venice"},{"Denver","Houston","New York"}};
public Testing()
{
super("JComboBox Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,100);
setLocation(400,300);
Container frame = getContentPane();
frame.setLayout(new FlowLayout());
aList = new JComboBox(aText);
aList.addItemListener(this);
frame.add(aList);
bList = new JComboBox(bText[0]);
bList.addItemListener(this);
frame.add(bList);
setContentPane(frame);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource() == aList)
{
bList.removeAllItems();
int index = aList.getSelectedIndex();
for(int x = 0; x < bText[index].length; x++) bList.addItem(bText[index][x]);
}
}
public static void main(String[] args){new Testing().setVisible(true);}
}