How to select a row table if a condition is specified?

I have a jtable that consists of columns:

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

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

  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
java swing renderer jtable
source share
1 answer

Since you want to select each cell on the same line as Qualifying Expiry , you must override prepareRenderer() , as shown in this and discussed in this Q & A. You can determine the appropriate string using Calendar. getInstance() methods Calendar. getInstance() Calendar. getInstance() , and you can change the color using the setBackground() rendering method.

+3
source share

All Articles