JComboBox的removeAllItems()提示下标越界怎么办?
如题,调用JComboBox的removeAllItems()方法总是报错java.lang.ArrayIndexOutOfBoundsException,要怎么解决?...
如题,调用JComboBox的removeAllItems()方法总是报错java.lang.ArrayIndexOutOfBoundsException,要怎么解决?
展开
2个回答
展开全部
/**清除之前,先移走行为监听.**/
ActionListener[] actions =jcb.getActionListeners();
for (int i=0;i<actions.length;i++)
{
jcb.removeActionListener(actions[i]);
}
jcb.removeAllItems();
for (int i=0;i<items.length;i++)
jcb.addItem(items[i]);
/**还原之前的监听.**/
for (int i=0;i<actions.length;i++)
{
jcb.addActionListener(actions[i]);
}
ActionListener[] actions =jcb.getActionListeners();
for (int i=0;i<actions.length;i++)
{
jcb.removeActionListener(actions[i]);
}
jcb.removeAllItems();
for (int i=0;i<items.length;i++)
jcb.addItem(items[i]);
/**还原之前的监听.**/
for (int i=0;i<actions.length;i++)
{
jcb.addActionListener(actions[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询