我的JList怎么动态填入条目?请帮忙看看

wingafra 2002-01-27 02:12:09
有段程序,结构如下:
class Test extends JFrame{
Vector vList = new Vector();
JList lLine = new JList(vList);
....
public Test() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
...
this.getContentPane().add(lLine, new XYConstraints(107, 133, 186, 234));
}

//事件处理部分,选出lLine构造方法中的vList
void cbPS_itemStateChanged(ItemEvent e) {
try{
if(cbPS.getSelectedIndex()>0){

sSql = "select b.point_name from power_station a ,point_index b"
+ " where a.ps_no = b.ps_no and a.ps_name ='"+cbPS.getSelectedItem()+"'";
connDB conTmp = new connDB();

Statement stmtTmp = conTmp.conn.createStatement();
ResultSet rsTmp = stmtTmp.executeQuery(sSql);
while(rsTmp.next()){
String sItem = "" + rsTmp.getString("point_name");
vList.addElement(sItem);
}

this.getContentPane.add(lLine, new XYConstraints(107, 133, 186, 234));
...
}
}catch(Exception ee) {ee.printStackTrace();}
}

}

以上程序编译通过,但是在下拉框事件响应时,lLine中的值没有被填充,仍是空,为什么?怎么解决?

另外,我的下拉框事件为什么总响应两次?
...全文
57 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wingafra 2002-01-28
  • 打赏
  • 举报
回复
请大家指点

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧