您的位置:首页 > 其它

swing 组合框(下拉框)选中记录,设置下拉列表

2015-10-22 08:55 856 查看
//选中表中记录,并供下方修改或删除
private void bookTableMouseClicked(java.awt.event.MouseEvent evt) {
//获取选中的行号,根据行号获取每一列的值
int row = this.bookTable.getSelectedRow();
this.bookIdTxt
.setText((Integer) this.bookTable.getValueAt(row, 0) + "");
this.bookNameTxt.setText((String) this.bookTable.getValueAt(row, 1));
this.bookAuthorTxt.setText((String) this.bookTable.getValueAt(row, 2));
//this.sex_man.setText((String) this.bookTable.getValueAt(row, 3));
String sex = (String) this.bookTable.getValueAt(row, 3);
if ("男".equals(sex)) {
this.resetSex();
this.sex_man.setSelected(true);
} else if ("女".equals(sex)) {
this.resetSex();
this.sex_female.setSelected(true);
}

//注意这里+""转换成字符
this.bookPriceTxt.setText((Float) this.bookTable.getValueAt(row, 4)
+ "");
this.bookDescTxt.setText((String) this.bookTable.getValueAt(row, 5));
String table_BookTypeName = (String) this.bookTable.getValueAt(row, 6);

//选中记录,设置下拉列表
int n=this.bookTypeList.getItemCount();
//System.out.println(n);
for (int i=0;i<n;i++){
//System.out.println(this.bookTypeList.getItemAt(i));
BookType bookType=(BookType) this.bookTypeList.getItemAt(i);
if(bookType.getBookTypeName().equals(table_BookTypeName)){
this.bookTypeList.setSelectedIndex(i);
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: