我的JList怎么动态填入条目?请帮忙看看
有段程序,结构如下:
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中的值没有被填充,仍是空,为什么?怎么解决?
另外,我的下拉框事件为什么总响应两次?