2

I need help.

I have two tables. enter image description here

In the instruction table., each row must be highlighted according to what instruction is being execute in the pipeline stages. Say for example., at time t10, I5 is in IS stage, so I5 in instruction table must be highlighted or the color of the row in instruction table must be change.say, I5 row is color red, I6 row is color pink, I7 is color green, I8 is color gray, I9 is color orange.

I really need your expertise., thank you.. :)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Celine
  • 475
  • 1
  • 7
  • 7
  • 3
    Have you gone through the [JTable tutorial](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html)? This sort of thing is well explained there. Please check it out, in particular the section on creating custom renderers. It sounds as if you will want to read the [SwingWorker Tutorial](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) as well since your "instruction execution" will likely need to be done on a background thread. – Hovercraft Full Of Eels Mar 21 '12 at 13:25
  • 2
    there could be issue with used Look and Feel, this is plain Nimbus or some of Custom L&F based on Nimbus ... – mKorbel Mar 21 '12 at 13:28
  • Ah, I was hoping our resident JTable rendering expert would show up, and he has! – Hovercraft Full Of Eels Mar 21 '12 at 13:31

1 Answers1

3

Please try this using custom rendered which will solve your problem easily

JTable myTable = new JTable();
// You can specify the columns you need to do the required action
myTable.getColumnModel().getColumn(0).setCellRenderer(new MyRenderer());

public class MyRenderer extends DefaultTableCellRenderer {

    // This is a overridden function which gets executed for each action to
    /// your Jtable
    public Component getTableCellRendererComponent (JTable table, 
        Object obj, boolean isSelected, boolean hasFocus, int row, int column) {

       // Use this row, column to change color for the row you need, e.g.
        if (isSelected) { // Cell selected
           cell.setBackground(Color.green);
        }
    }
} 

Note: this renderer can be used for more than doing color highlighting, please refer custom Jtable rendering. For timing your changes in response to the queue, you can schedule it in a separate thread.

kba
  • 19,333
  • 5
  • 62
  • 89
Ashok Raj
  • 444
  • 6
  • 25