如果给出条件,如何突出显示行表? [英] How to Highlight row table if given a condition?

查看:99
本文介绍了如果给出条件,如何突出显示行表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由列组成的jtable:

I have a jtable which is consists of columns :

C No, Borrower, Market, Loan, Start, Daily, Expiry

如果当前日期距离日期内的5天,我如何突出显示表格行列'到期'

how can i highlight the table row if the current date is 5 days away from the date inside the column 'expiry'?

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");     
            Calendar cal  = Calendar.getInstance();           
            String expDateString = sdf.format(cal.getTime()).toString();
            System.out.println(expDateString);
             String nana = tableSummary.getModel().getValueAt(row, 6).toString();
            System.out.println(nana);


            for(int i=0; i<=tableSummary.getRowCount()-1; i++){

                   if(nana.compareTo(expDateString)>=0){                           
                       rowrenderer.setBackground(Color.RED);

                   }
             }


推荐答案

因为您要突出显示同一行中的每个单元格作为符合条件的 Expiry ,您应该覆盖 prepareRenderer() ,如示例所示,并在此Q&A 。您可以使用 Calendar的方法确定匹配的行。 getInstance(),您可以使用渲染器的 setBackground()方法更改颜色。

Because you want to highlight every cell in the same row as a qualifying Expiry, you should override prepareRenderer(), as shown in this example and discussed in this Q&A. You can determine a matching row using the methods of Calendar. getInstance(), and you can change the color using the renderer's setBackground() method.

这篇关于如果给出条件,如何突出显示行表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆