-2

In Netbeans(IDE 7.0) at advanced search keyrealese event I want to change the Jtable row colors under the condition.If system date(current date) is equal to that table(in database) coloumn name "Date" and system time(current time) is less than to table coloum name "Time" then I want to display that row in Green color else want to display in Red colour.Please share your knowledge.It will very usefull to me.:.respect.

hints-The table name is in DB is "Vehicle",The coloumns are "Date","Time","Veh_No","Model".. I think we want to use "If" condition,and create two other variables to store system date and system time before give and condition.Plz help me..

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • possible duplicate of [Change the background color of a row in a JTable](http://stackoverflow.com/questions/3875607/change-the-background-color-of-a-row-in-a-jtable). Sigh, similar questions get asked (and answered) nearly on a daily basis - why don't you do at least a _little bit_ of research before duplicating them? – kleopatra Sep 03 '13 at 11:28

1 Answers1

0
  1. Write a custom cell renderer.

    public class CustomCellRenderer implements TableCellRenderer {

    public Component getTableCellRendererComponent(....) { Color color = getRowBackGroundColor(table, value, isSelected, hasFocus, row, column); comp.setBackground(color); return comp; } }

  2. Override the prepareRenderer method of JTable. Logic remains similar to getTableCellRendererComponent().

I prefer overriding the prepareRenderer method.

Guest
  • 33
  • 1
  • 1
  • 4