Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable row settings

Status
Not open for further replies.

FlorisF

MIS
Joined
Jun 13, 2001
Messages
1
Location
US
Hi,

I would like to set the font of an entire row in a JTable to Bold. I can't find the way to do this from the descriptions. Could someone who knows about this be so kind to provide some info?

Thanks a lot,

Floris.
 
Try to add a custom table cell renderer - an inner class like the following (write or paste this like you'd normally write a method):

private class MyRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
Font oldFont = component.getFont();
Font newFont = oldFont;
if (column == 1)
{
newFont = new Font(oldFont.getName(), Font.BOLD, oldFont.getSize());
}
component.setFont(newFont);
return component;
}
}

Of course not only column 1 is possible here ;-)
You can then use the following on the table you want to use (supposed it's called "table"):

table.setDefaultRenderer(Object.class, new MyRenderer());

Hope this helps...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Oh, I forgot, you'll have to import javax.swing.DefaultTableCellRenderer for this to work.
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top