Update:
I found a partial solution in this answer here by adding the following code:
class CustomRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(new java.awt.Color(255, 72, 72)); return c; } }
And then pass it to my JTable object:
jTable2.setDefaultRenderer(String.class, new CustomRenderer());
This works correctly, and now the table rows are colored red:
The only thing I need to know now is to limit the coloring to one line and one cell.
After further research, I need the setCellRender()
method so that I can set up custom rendering in a specific cell, but this method does not exist.
Question:
I want to create a visual component for phased execution of pseudocode.
For this, I created JTable, and now I'm looking for ways to select each row (or cell, since there is only one column) to display which row is running.
I have included the layout below in the final GUI. As you can see in the Pseudocode panel, I highlighted the last line.
Please ignore the arrows that they are not strictly related to the issue.
I started implementing the layout in Netbeans Matisse (this is 1 of 3 algorithms). However, I do not know how to select one line of code line 1
in the JTable component.
Would it be easier to use a different type of component?
Later, I will also need to repaint individual cells, as shown in the Table JPanel layout. How can this be implemented?