How to Highlight row table if given a condition?

百般思念 提交于 2019-12-02 13:21:56

问题


I have a jtable which is consists of columns :

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

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);

                   }
             }

回答1:


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.



来源:https://stackoverflow.com/questions/9714110/how-to-highlight-row-table-if-given-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!