looping around a table renderer, is it possible?
i am trying to get rows to change colours, red, green or white. Depending on whether the value in the cells has increased or decreased etc.
I have it on a loop that currently prints out the previous, current value, and if its increased or not. As it stands i just have a value inserting into a cell but not updating a colour.
the code i have for the timer and method that updates the cell and compares values is...
Code:
private void updateStockPrices() {
for (int i = 0; i < stockBeans.size(); i++) {
Object obj1 = getData(jTable, i, 1);
String obj2 = obj1.toString();
float newVal = Float.parseFloat(obj2);
StockBean currentBean = stockBeans.get(i);
final StockBean currentStockBean = stockTickerDAO.refreshStockInfo(currentBean);
System.out.println(currentStockBean.symbol);
tableModel.setValueAt(currentStockBean.symbol, i, 0);
tableModel.setValueAt(currentStockBean.price, i, 1);
tableModel.setValueAt(currentStockBean.change, i, 2);
float stock = currentStockBean.price;
System.out.println("Comparing " + stock + " and " + newVal);
if (stock > newVal) setData("INCREASE", i, 3);
if (stock < newVal) setData("DECREASE", i, 3);
if (stock == newVal)setData("NO CHANGE", i, 3);
}
}
The table renderer code is..
Code:
JeksTable jTable = new JeksTable(tableModel){
public Component prepareRenderer
(TableCellRenderer renderer,int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
if (Index_row % 1 == 0 && isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.LIGHT_GRAY);
}
else {
comp.setBackground(Color.white);
}
return comp;
}
}
Can i have 3 different renderers and call the appropriate one each time the above if statements are run?
or does anyone have a more simple solution?
Thanks