|
-
November 23rd, 2008, 05:06 PM
#1
colouring cells in JTable
Hello,
I am using Swing and JTables.
What I would like to do is to pass to my function colourCells(){..} a list of cells and a colour to colour them with. For example for a given row in my JTable, I would like some of the cells to be one colour and the rest another colour, based on some condition - which always changes.
I have tried to extend the DefaultTableCellRenderer and to implement the following function, which is called from my function colourCells() when I iterate through the list of cells I would like to colour:
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {...}
As far as I can see, this renders all the cells in my JTable over and over again based on some colouring rules I put in this function:
eg. :
if(value instanceof String){
cell.setBackground(Color.YELLOW);
}else{
cell.setBackground(Color.WHITE);
}
now I don't want all my cells the same colour! Like I said above, the list of cells I create should be associated with a certain colour.
has anyone every tried to colour certain cells in a JTable? and how can you make this colouring dynamic (ie. passing in your own list of random cells to colour along with the chosen colour) ?
thank you for your help in advance!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|