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);
}
}
}
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);
}
}
}
相关文章推荐
- Cocoapods
- Weka报错"Unknow data type INT. Add entry in weka/experiment/DatabaseUtils.props"
- 【codevs 2451】互不侵犯king 状压dp
- swing 组合框(下拉框)获取选中的值
- ssh登录会话保持时间太短解决方法之一
- String当中的高效函数(优化)
- 简单的分析洋葱淘app这款产品
- swing 组合框(下拉框)填充默认值
- 第17章 内存映射文件(1)_内存映射文件简介
- js 传递方法
- 冒泡排序法
- 【luogu P1440】求(DQ)M区间内的最小值
- 解决VS2010链接错误:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- extjs 4.2后台传递的时间字符串2015-01-02会自动变为时间
- 黑马程序员----总结2(创建线程、同步、线程间通讯)
- spring软件地址
- 二叉树之实现排序二叉树
- position
- swing 单选框(互斥buttonGroup),设置默认值,获取值
- 黑马程序员-OC回顾-基础语法(二)