Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 根据到期日期更改jtable中的单元格背景_Java_Jframe_Jtable - Fatal编程技术网

Java 根据到期日期更改jtable中的单元格背景

Java 根据到期日期更改jtable中的单元格背景,java,jframe,jtable,Java,Jframe,Jtable,目前,我正在尝试制作一个到期日检查器,用户可以在jtable中输入项目的最佳截止日期。该程序将输出一个红色或绿色的单元格,通过将其与当前日期进行比较来确定该单元格是否过期。 这是我正在使用的代码:(由于某种原因,没有发生颜色变化) public void dateComparer(TableCellRenderer渲染器,int行,int列){ SimpleDataFormat sdf=新的SimpleDataFormat(“日/月/年”); Calendar cal=Calendar.getI

目前,我正在尝试制作一个到期日检查器,用户可以在jtable中输入项目的最佳截止日期。该程序将输出一个红色或绿色的单元格,通过将其与当前日期进行比较来确定该单元格是否过期。 这是我正在使用的代码:(由于某种原因,没有发生颜色变化)

public void dateComparer(TableCellRenderer渲染器,int行,int列){
SimpleDataFormat sdf=新的SimpleDataFormat(“日/月/年”);
Calendar cal=Calendar.getInstance();
String expDateString=sdf.format(cal.getTime());
当前日期=新日期(expDateString);
日期BBD=新日期(jtableMain.getModel().getValueAt(第3行).toString());

对于(int i=0;i您到目前为止尝试过什么?发布您的代码!当您运行它时会发生什么?您希望发生什么?任何错误?堆栈跟踪?好的,我发布了我的代码,目前它只是将数据添加到jtable中,但是我希望BBD中高于或低于到期日期的单元格更改颜色(红色/绿色)你不应该在检查中使用循环索引变量吗?到目前为止你尝试了什么?发布你的代码!当你运行它时会发生什么?你希望发生什么?任何错误?堆栈跟踪?好的,我发布了我的代码,目前它只是将数据添加到jtable中,但是我希望BBD中高于或低于到期日期的单元格更改e color(红色/绿色)您不应该在检查中使用循环索引变量吗?
    public void dateComparer(TableCellRenderer renderer, int row, int column){
     SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");     
     Calendar cal  = Calendar.getInstance();           
     String expDateString = sdf.format(cal.getTime());

     Date current = new Date(expDateString);
     Date BBD = new Date(jtableMain.getModel().getValueAt(row,3).toString());

     for(int i=0; i<=jtableMain.getRowCount()-1; i++){
         if(BBD.before(current))
            setBackground(Color.GREEN);
         if(BBD.after(current))
             setBackground(Color.RED);

   }