0
public class dropit extends JFrame implements ActionListener{
JComboBox lis,pop;
Map<String,String[]>map=new TreeMap<String,String[]>();
JTextField tf;
String days[]={"sun","mon","tue","wed","thur","fri","sat"};
String mon[]={"man","van"};
String tue[]={"car","bus"};
dropit()
{
setLayout(null);
tf=new JTextField();
tf.setBounds(50, 50, 100, 100);
add(tf);
map.put("mon", mon);
map.put("tue",tue);
lis=new JComboBox(days);
lis.setSelectedItem(4);
lis.addActionListener(this);
lis.setBounds(100,100,100,100);
add(lis);
/*pop=new JComboBox();
pop.setBounds(200,100 , 100, 100);
add(pop);*/
setVisible(true);
setSize(500,500);
}
public void actionPerformed(ActionEvent e)
{
lis=(JComboBox) e.getSource();
String name=(String) lis.getSelectedItem();
tf.setText(name);
Iterator<String>iter=map.keySet().iterator();
while(iter.hasNext())
{
String arryname=iter.next();
String []array=map.get(arryname);
if(arryname.contains(name))
{
pop=new JComboBox(array);
pop.setBounds(200,100 , 100, 100);
add(pop)
}}
pop.repaint();
pop.revalidate();
}
public static void main(String[] args) {
new dropit();
}}
組合框是可以正常使用,但在接下來的組合框的填充值是單純的工作首次如何刷新每個選擇的Jcombobox?
我試圖重新繪製重新驗證,但沒有工作
幫我解決這個.Thanks在提前
它不工作... – sukesh
@sukesh我剛剛編輯帖子。你的IDE是什麼?什麼是錯誤? –
我正在使用eclipse 錯誤是 第二個組合框不顯示 – sukesh