Jtable表格失焦,停止可编辑

在项目过程中,常常会遇到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方法很好用。

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值