1

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

                   }
             }
zairahCS
  • 325
  • 5
  • 11
  • 17
  • You've given no information that anybody could use to help you. Are you producing HTML, or is this a Swing app? What js framework are you using, if any? Are you running Tomcat and JSPs, or another JEE container? Please read the [FAQ] and [ask] before posting. – Jim Garrison Mar 15 '12 at 04:52
  • 2
    @JimGarrison: Right there in the unedited question it says "jtable" so obviously this is related to Swing. It is a reasonable question which, I think, has enough information to be answered. Might be a good idea to withdraw the down-vote. – Steve Mar 15 '12 at 05:09
  • Oh i'm sorry. Yeah it is in java, related to Swing since it is jtable. – zairahCS Mar 15 '12 at 05:18
  • 1
    `jtable` is overloaded. There's even a jtable.org for a JQuery plugin by that name. – Jim Garrison Mar 15 '12 at 06:47
  • be sure you understand how the renderer mechanism is working http://docs.oracle.com/javase/tutorial/uiswing/components/table.html (looping through the values and set some backgrounds doesn't make any sense) – kleopatra Mar 15 '12 at 13:11

1 Answers1

3

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • can i ask for an example? i am not quite familiar yet with cellrenderer. thanks – zairahCS Mar 15 '12 at 14:28
  • Oops, sorry for the broken link; I've updated the answer above. The best examples are in [*Table Row Rendering*](http://tips4java.wordpress.com/2010/01/24/table-row-rendering/). – trashgod Mar 15 '12 at 18:18