The Artima Developer Community
Sponsored Link

Java Answers Forum
Rendering a cell in JTable

2 replies on 1 page. Most recent reply: Jan 31, 2003 3:51 AM by Sylvia van der Velde

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
prashanth

Posts: 2
Nickname: prash29
Registered: Jan, 2003

Rendering a cell in JTable Posted: Jan 31, 2003 2:47 AM
Reply to this message Reply
Advertisement
I have a JTable which is populated with rows from the database.
I want to change the background colour of the first row in the table while the other rows should be of some other colour.
Can anyone send a sample code to do this..
I tried with using the cell renderer , however it applies to all the rows in a particular column and does not limit to a single cell.


Sylvia van der Velde

Posts: 4
Nickname: rommie
Registered: Jan, 2003

Re: Rendering a cell in JTable Posted: Jan 31, 2003 3:49 AM
Reply to this message Reply


public class LabelRenderer extends JLabel implements TableCellRenderer{


public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

if ( row == 0 )
super.setBackground( Color.green );
else
super.setBackground( Color.blue ); // if you really take this colors ... be damned :-)

}

}



Hope this helps,
Rommie.

Sylvia van der Velde

Posts: 4
Nickname: rommie
Registered: Jan, 2003

Re: Rendering a cell in JTable Posted: Jan 31, 2003 3:51 AM
Reply to this message Reply
And if you want to limit it to a single cell, just add an if for the column number, too.

Rommie.

Flat View: This topic has 2 replies on 1 page
Topic: Constructor not being called Previous Topic   Next Topic Topic: Security and JMF in applets

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use