This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
hi friends i want to change the color of a particular row dynamically.right now i can able to change all the row.how to capture a particular row and change the color dynamically. plz help me with some example bye
Julie Stella
Greenhorn
Joined: Jan 12, 2001
Posts: 5
posted
0
This is an older post...did you get it resolved? If not, you will want to create a custom TableCellRenderer that assigns color to a specific row before painting. Just put your code in getTableCellRendererComponent. I have examples but not with me today. If you reply to this post, I will post them for you. If you've already solved your problem, good for you! Stella
wip siva
Ranch Hand
Joined: Nov 03, 2000
Posts: 36
posted
0
hi stella thanx a lot. i can able to change the color of one cell.not the entire row. badly i need it.i have a demo on monday.plz give me the sample code . i just put my code . and i have one more major bug.whenever the table gets updated by new data its not repainting properly throwing some nullpointer exception. i trying it if u have any idea.plz let me know. my id is . 123knock@usa.net thanx in advance.
This is the exception i am getting while updating the table. Exception occurred during event dispatching: java.lang.NullPointerException at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java, Comp iled Code) at javax.swing.plaf.basic.BasicTableUI.paintRow(BasicTableUI.java, Compi led Code) at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java, Compiled Code) at javax.swing.plaf.ComponentUI.update(ComponentUI.java, Compiled Code) at javax.swing.JComponent.paintComponent(JComponent.java, Compiled Code) at javax.swing.JComponent.paint(JComponent.java, Compiled Code) at javax.swing.JComponent.paintChildren(JComponent.java, Compiled Code) at javax.swing.JComponent.paint(JComponent.java, Compiled Code) at javax.swing.JViewport.paintViaBackingStore(JViewport.java, Compiled C ode) at javax.swing.JViewport.paint(JViewport.java, Compiled Code) at javax.swing.JComponent.paintWithBuffer(JComponent.java, Compiled Code ) at javax.swing.JComponent._paintImmediately(JComponent.java, Compiled Co de) at javax.swing.JComponent.paintImmediately(JComponent.java, Compiled Cod e) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java, Com piled Code) at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System EventQueueUtilities.java, Compiled Code) at javax.swing.SystemEventQueueUtilities.processRunnableEvent(SystemEven tQueueUtilities.java, Compiled Code) at javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(Sys temEventQueueUtilities.java, Compiled Code) at java.awt.Component.dispatchEventImpl(Component.java, Compiled Code) at java.awt.Component.dispatchEvent(Component.java, Compiled Code) at java.awt.EventQueue.dispatchEvent(EventQueue.java, Compiled Code) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java, C ompiled Code) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92) at java.awt.EventDispatchThread.run(EventDispatchThread.java:83) This is my File *************** import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; import javax.swing.table.AbstractTableModel; import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.LinkedList; import java.util.Collections; import java.util.Enumeration; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.plaf.ComponentUI.*; import java.awt.Component.*; import com.wipro.osssmart.multicast.*;
/** This Method to upDate the data on the table * This will be called when any one the Application is selected from left Panel. **/ public void updateData(OssEvent event) { try { if(event.getActionType()== OssEvent.APPLICATION) { appVector.removeAllElements(); appVector = event.getData();
} else if(event.getActionType() == OssEvent.FILTEROR) { msgVector = event.getData(); errorVector = event.getErrorVector(); orcondition = true; andcondition = false; } else if (event.getActionType()== OssEvent.FILTERAND) { msgVector = event.getData(); errorVector = event.getErrorVector(); andcondition = true; orcondition = false; } else if(event.getActionType()==OssEvent.STOP) { orcondition = false; andcondition = false; } //Then it calls the start method start(); }catch(Exception e) { e.printStackTrace(); System.out.println("Exception in updateData:"+e.getMessage()); } } /** This method gets the Messages as parameter and adds to the vector * Then the vector added to the TableMOdel by using addRow method. **/ public void addRow(Message msg) { try { Vector vector = new Vector(); vector.addElement((String)msg.applicationName); vector.addElement((String)msg.ossName); vector.addElement((String)msg.clusterName); vector.addElement((String)msg.serviceName); vector.addElement((String)msg.messageType); vector.addElement((String)msg.errorType); vector.addElement((String)msg.messageText); // if(SwingUtilities.isEventDispatchThread()) model.addRow(vector); ossTable.updateUI(); //ossTable.validate(); }catch(NullPointerException e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
/** * This Method to set the preferedsize of the table column **/ public void sizeColumn() { for(int i=0; i< ossTable.getColumnCount() ;i++) { TableColumn objLeftEndColumn = ossTable.getColumnModel().getColumn( i ); objLeftEndColumn.setPreferredWidth(objLeftEndColumn.getWidth() + 50 ); } } /** This Method to start the Thread **/ public void start() { test=false; if(thread.isAlive()) { try { thread.interrupt(); } catch(Exception e) { } } if(listThread.isAlive()) { try { listThread.interrupt(); } catch(Exception e) { } } if(list.size() != 0) { list.clear() ; } if(!thread.isAlive()) thread.start(); } /** This class Start of thread1 * This thread used to receive the data * from the hub. **/ private class thread1 extends Thread { private Message preMessage = null; private Message msg1 = null; public thread1() { } public void run() { while(true) { Reciever cl = new Reciever(); //Reading data from OssHub and storing it in a String object msg1= cl.read(); if(preMessage == null ) { list.addLast(msg1); preMessage = msg1; } else if( msg1.applicationName.trim().compareTo(preMessage.applicationName.trim()) != 0 ) { list.addLast(msg1); preMessage = msg1; } else { System.out.println("Adding thread1" ); } try { this.sleep(400); } catch(Exception e) { } if(!test) { if(list.size() != 0) { if(!listThread.isAlive()) listThread.start(); test = true; } } } } }// End of class thread2 /** This class Start of thread2 * This thread used to put the data * On the table. **/ private class thread2 extends Thread { //private Message msg; public thread2() { msg = new Message(); } //Overrided run method from Thread class public void run() { try { while( true ) { try { msg = (Message)list.removeFirst(); } catch(Exception e) { msg=null; } if(msg != null) { if ((msg.applicationName).equalsIgnoreCase(("System").trim())) { addRow(msg); //model.fireTableDataChanged(); } else { if(appVector.indexOf((msg.applicationName).trim()) != -1) { if (andcondition == true) { if(errorVector.indexOf(msg.errorType.trim()) != -1 && msgVector.indexOf(msg.messageText.trim()) != -1 ) { addRow(msg); //model.fireTableDataChanged(); } else if(errorVector.size() == 0 && msgVector.indexOf(msg.messageText.trim()) != -1 ) { addRow(msg); //model.fireTableDataChanged(); } else if(errorVector.indexOf(msg.errorType.trim()) != -1 && msgVector.size() == 0) { addRow(msg); //model.fireTableDataChanged(); } } else if (orcondition == true) { if(msgVector.indexOf(msg.messageText.trim()) != -1 ) { addRow(msg); //model.fireTableDataChanged(); } else if(errorVector.indexOf(msg.errorType.trim()) != -1) { addRow(msg); //model.fireTableDataChanged(); } } else { addRow(msg); //model.fireTableDataChanged(); } } } } scrollBar.setValue(model.getRowCount()* ossTable.getRowHeight()) ; try { this.sleep(100); } catch(Exception e) { } } } catch(Exception e) { e.printStackTrace(); System.out.println("Exception in Thread"+e.getMessage()); } } }// End of class thread2 //scrollBar.updateUI(); public void tableChanged(TableModelEvent e) { try { if((msg.errorType).equalsIgnoreCase(("Error Type2").trim())) { //ossTable.setForeground(Color.red); } else { ossTable.setForeground(Color.blue); } }catch(Exception a) { //a.printStackTrace(); } } class ColoredTableCellRenderer extends DefaultTableCellRenderer { public void setValue(Object value) { setText((String)value); if(((String)value).equals("Error Type2")) {
setForeground(Color.red); } else { setForeground(Color.blue); } } } }//End of MonitorTablePanel class
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.