Note that there are some explanatory texts on larger screens.

plurals
  1. POMark the duplicates in a JTable
    text
    copied!<p>I have created a <code>JTable</code> with the help of <code>AbstractTableModel</code>. I would like to mark (change the color of the cell) in a this <code>JTable</code> the third column which has the same entry as the second column. For example:</p> <p><img src="https://i.stack.imgur.com/OhaTr.png" alt="enter image description here"></p> <p>and so, with the help of this post <a href="https://stackoverflow.com/questions/13565703/check-duplicate-data-in-jtable-before-proceeding">Check duplicate data in jtable before proceeding</a></p> <p>I have came to this: </p> <pre><code> table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override 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); TreeSet&lt;Object&gt; set = new TreeSet&lt;Object&gt;(); for (int i=0; i&lt;model.getRowCount();i++){ Object obj = model.getValueAt(i,1); //(row, column) if(!set.add(obj)) { c.setBackground(new java.awt.Color(255, 72, 72)); } else{ c.setBackground(null); } } return c; } }); </code></pre> <p>But, although it seems that it correctly checks for each row (due to some printing I have done), nothing is colored. I would like to add, that the <code>JTable</code> that I have created is a <code>JTable</code> that always changes, meaning there are two buttons, for <code>PREVIOUS</code> and <code>NEXT</code>and this table always changes each form - also the number of the columns changes.</p> <p>If anything more is requested, I would edit my post.</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload