Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How i can change of a row or cell to my jTable?

Helppp

How i can change of a row or cell to my jTable?

i like to chage the font of a row to the jTable;

for exmple in this method i can just change the color of a sepecifiek colomn,
but i can't change the the color of a specifieke row?

----
public void colorTable(){

TableColumnModel columnModel = jTable1.getColumnModel();
//CellEditor celedit = jTable1.getCellEditor(0, 0);
//TableModel tblcellrender = jTable1.gettgetCellEditor();
//for(int i=0; i<2; i+=1)
//{

columnModel.getColumn(0).setCellRenderer(new DefaultTableCellRenderer()

{
public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component comp = super.getTableCellRendererComponent(jTable1,
value,false,false,2,0);

String optionValue;
optionValue = jTable1.getValueAt(row, column).toString();
System.out.println("row is " +row +column+ " " + optionValue);
//if (optionValue != "")
if (column == 0)
{
System.out.println("grey Blue");
comp.setForeground(Color.blue); //.setBackground(Color.orange);
}
else {
System.out.println("white color");
comp.setBackground(Color.white);
}
return comp;
} //end of getTableCellRendererComponent
});

//} //end of for
} //end of colorTable
----
thanks!!!
[1439 byte] By [Dries] at [2007-11-9 21:19:04]
# 1 Re: How i can change of a row or cell to my jTable?
What do you think the "row" parameter is for? (And apply your renderer to
the entire table, not just to one column.)

PC2

Dries <chdries@hotmail.com> wrote in message news:3a6c28a2@news.dev-archive.com...
>
> Helppp
>
> How i can change of a row or cell to my jTable?
>
> i like to chage the font of a row to the jTable;
>
> for exmple in this method i can just change the color of a sepecifiek
colomn,
> but i can't change the the color of a specifieke row?
>
> ----
> public void colorTable(){
>
> TableColumnModel columnModel = jTable1.getColumnModel();
> file://CellEditor celedit = jTable1.getCellEditor(0, 0);
> file://TableModel tblcellrender = jTable1.gettgetCellEditor();
> file://for(int i=0; i<2; i+=1)
> file://{
>
>
> columnModel.getColumn(0).setCellRenderer(new
DefaultTableCellRenderer()
>
> {
> public Component getTableCellRendererComponent(JTable table,
Object
> value, boolean isSelected, boolean hasFocus, int row, int column)
> {
> Component comp =
super.getTableCellRendererComponent(jTable1,
> value,false,false,2,0);
>
>
> String optionValue;
> optionValue = jTable1.getValueAt(row, column).toString();
> System.out.println("row is " +row +column+ " " +
optionValue);
> file://if (optionValue != "")
> if (column == 0)
> {
> System.out.println("grey Blue");
> comp.setForeground(Color.blue);
file://.setBackground(Color.orange);
> }
> else {
> System.out.println("white color");
> comp.setBackground(Color.white);
> }
> return comp;
> } file://end of getTableCellRendererComponent
> });
>
> file://} file://end of for
> } file://end of colorTable
> ----
> thanks!!!
>
Paul Clapham at 2007-11-11 23:06:16 >