Help coderanch get a
new server
by contributing to the fundraiser

Rajan

Greenhorn
+ Follow
since Jun 19, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rajan


hi cs,
You can set your scrollableviewport size.
create the dimension accoding to number of the row and width of your table.
Dimension dim = new Dimension(row size, width)
table.setPreferredScrollableViewportSize(dim).
or
table.setPreferredScrollableViewportSize(table.getPreferredSize()).

or
Dimension size = table.getPreferredScrollableViewportSize();
table.setPreferredScrollableViewportSize (new Dimension(Math.min(getPreferredSize().width, size.width), size.height);
Hope this will meet your requirement.
23 years ago
Hi Paul,
I have to do it dynamically. How can i pass the row index so that i can check with the getTableCellRendererComponent method's row(int).
Once after creating the table, according to certain creteria i have change the color of the corresponding row.
Can help me in this issue.
thanks
Rajan

23 years ago
Hi all,
Can any body help me in setting different color for rows. I have done it for column.
thanks
23 years ago
Hi Kate,
I would like to know how do you associate your NumberCellRenderer to the cells of the taable.
inorder to associate the renderer, i have done it by obtaining the columnModel of the table, with that get the column from the model by using index and set the renderer to the column(which the renderer is set to all the cells of the column).
code:
table.getColumnModel().getColumn(index).setCellRenderer(numbercellrenderer).

if you have done in different way let me know. how u have associated your renderer to the cell.

thanks......
23 years ago
Hi Kate
I have overridden the default cell renderer with mine, in which i have set both foreground as well as background color.
you can set the color in either in your NumberCellRenderer constructor or in getTableCellRendererComponent of NumberCellRenderer.
Code:
setBackground(Color.white);
setForeground(Color.red);

I suppose, is this your renderer declaration
class NumberCellRenderer extends JLabel implements TableCellRenderer{}
Overriding of DefaultCellRenderer is customize you cells in the table. Method getTableCellRendererComponent is used when you set the column with your NumberCellRenderer.

23 years ago
Hi Kate
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)

You can check whether the Object(value) is an instance of an integer, if so you can do the process of elimination of negative sign and set the value with the method
setText(your value);
if it not an instance of integer then
default : setText(value.toString());

23 years ago