Results 1 to 2 of 2
- 10-14-2010, 10:19 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
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...
The table renderer code is..Java 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); } }
Can i have 3 different renderers and call the appropriate one each time the above if statements are run?Java 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; } }
or does anyone have a more simple solution?
Thanks
- 10-14-2010, 02:28 PM #2
1. By convention, Java variable names (that includes method and constructor parameters) start with a lowercase letter. More on
Code Conventions for the Java(TM) Programming Language: Contents
2. Do you know what the modulo operator % does? What's the remainder when you divide an int by 1?
3. We have no idea of the functionality of the class JeksTable.
You don't *call* a renderer. You can set different renderers to different columns, and you can return different components from the getTableCellRendererComponent(...) method.Can i have 3 different renderers and call the appropriate one each time the above if statements are run?
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
dbLast edited by DarrylBurke; 10-14-2010 at 02:51 PM.
Similar Threads
-
ProgressBar Renderer?
By greatmajestics in forum AWT / SwingReplies: 2Last Post: 04-20-2010, 04:12 AM -
ProgressBar renderer Help?
By greatmajestics in forum AWT / SwingReplies: 0Last Post: 04-17-2010, 09:39 PM -
table renderer problem in nimbus look and feel
By Allgorythm in forum New To JavaReplies: 0Last Post: 02-22-2010, 12:20 PM -
Custom renderer (almost works)
By geforce2000 in forum AWT / SwingReplies: 11Last Post: 12-13-2009, 09:15 PM -
how to use renderer in JTable
By sunilpatel28 in forum Advanced JavaReplies: 0Last Post: 12-09-2008, 08:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks