在项目过程中,常常会遇到ctable点击保存的时候,点击保存前的最后一个编辑格子的内容为空。
如何使表格的编辑状态取消,达到失焦的效果?
如图:
要求前三个字段不能为空,最后一个字段允许为空。
如何让jtable停止编辑状态,并且能让当前值存在。(html中get就可以直接拿到,java不行)
boolean flag=false;
if(cTable1.getCellEditor()!=null){
flag=cTable1.getCellEditor().stopCellEditing();
}else{
flag=true;
}
if(!flag){
return;
}
int tableColNum = cTable1.getRowCount();
for (int i = 0; i < tableColNum; i++) {
String descript = cTable1.getValueAt(i, 1).toString();
String startday = cTable1.getValueAt(i, 2).toString();
String endday = cTable1.getValueAt(i, 3).toString();
for (int j = i + 1; j < tableColNum; j++) {
String ss_descript = cTable1.getValueAt(j, 1).toString();
String ss_startday = cTable1.getValueAt(j, 2).toString();
if (descript.equals(ss_descript)) {
Msg(descript + "有重复的描述,请检查!");
return;
}
if (startday.equals(ss_startday)) {
Msg(startday + "有重复的起始时间,请检查!");
return;
}
}
if(StringUtils.isBlank(descript)){
Msg("描述不能为空,请检查!");
return;
}
if(StringUtils.isBlank(startday)){
Msg("开始时间不能为空,请检查!");
return;
}
if(StringUtils.isBlank(endday)){
Msg("结束时间不能为空,请检查!");
return;
}
}
这里使用的stringUtils的isBlank方法很好用。