craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > UI , Look and Feel, Colors, Navigation, font, Locale Post New Topic   Post A Reply
row background/foreground printer friendly version
next newest post | next oldest post
Author Messages
ranjanjha
Private

Gender: Male
Location: Virginia
Registered: Jun 2004
Status: Offline
Posts: 9

Click here to see the profile for ranjanjha Visit http://www.jax.org Send email to ranjanjha Send private message to ranjanjha Find more posts by ranjanjha Edit or delete this message Reply w/Quote
Posted Tuesday, September 28, 2004 @ 20:23:34  

How can we select a row in QuickTable to change it's background or foreground color (for example, to get user's attention based on some error condition)?

Thanks for your help,
Ranjan

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, September 29, 2004 @ 13:54:44  

You have to use the CellPropertiesModel to change the cell foreground/background colors. The following is a sample implementation where the rows that to be highligted are stored in a Set object, if the row is in the Set, then red color will be applied to the row, if not the default color will be applied to the row.

class RowHighLighter extends CellPropertiesModel
{
HashSet rowsToBeHighligtedSet = new HashSet();

public void addRowsToBeHighlighted(int row)
{
rowsToBeHighligtedSet.add(new Integer(row));
}

public void removeRows(int row)
{
rowsToBeHighligtedSet.remove(new Integer(row));
}

public Color getForeground(int row, int col)
{
if( rowsToBeHighligtedSet.contains(new Integer(row)) )
return color.red;
else
{
//in all other cases let the cell have the default color
return null;
}

}

}

//apply the model to your dbtable
RowHighLighter rowHighLighter = new RowHighLighter()
dbTable.setCellPropertiesModel(rowHighLighter);

//add/remove rows to be highlighted
rowHighLighter.addRowsTBeHighlighted(1);

//if the colors are not applied once the above method is called,
//uncomment the following two lines
//dbTable.validate();
//dbTable.repaint();

JustinSkalka
Private First Class

Gender: Unspecified
Location: USA
Registered: Feb 2006
Status: Offline
Posts: 18

Click here to see the profile for JustinSkalka Send email to JustinSkalka Send private message to JustinSkalka Find more posts by JustinSkalka Edit or delete this message Reply w/Quote
Posted Tuesday, February 21, 2006 @ 16:08:57  

I can't get this to work.

I have the following code:

for (int r=1; r<dBTable1.getRowCount()+1; r++)
{
if (((String) dBTable1.getValueAt(r, 2)).equals("*INFO"))
{
rowHighLighter.addRowsToBeHighlighted(r);
}
}

followed by the validate and repaint, but nothing happens.

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, February 22, 2006 @ 16:30:09  

Can you add a debug statement

if (((String) dBTable1.getValueAt(r, 2)).equals("*INFO"))
{
System.out.println("Adding row" + r);
rowHighLighter.addRowsToBeHighlighted(r);
}

and check whether you really add the row.

If you are trying to check whether the data ends with "INFO", use endsWith() method instead of equals.

In your case you don't need to use the rowHighLighter class, instead you can put the logic into the CellPropertiesModel

Code:

class MyHighLighter extends CellPropertiesModel
{

public Color getForeground(int row, int col)
{
if (((String) dBTable1.getValueAt(row, 2)).endsWith("INFO"))
return color.red;
else
return null;
}

}

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios