Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know that an ActionListener will work well for a JCheckBox in a JTable since the check box isn't a real button but rather a rendering of a checkbox. Perhaps playing with the table model will help. For instance you can use HTML to display a strike through of Strings displayed in table cells. For instance below I create a custom TableModel that extends DefaultTableModel and holds rows with a Boolean object followed by objects of a TextWrapper class that I've created that changes its toString result depending on a boolean. </p> <p>e.g.,</p> <pre><code>import java.util.Vector; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class StrikeThroughRow { public static final Object[][] DATA = {{Boolean.TRUE, "Monday", "fe"}, {Boolean.FALSE, "Tuesday", "fi"}, {Boolean.TRUE, "Wednesday", "fo"}, {Boolean.FALSE, "Thursday", "fum"}, {Boolean.TRUE, "Friday", "foo"}}; public StrikeThroughRow() { } private static void createAndShowUI() { JTable table = new JTable(new StrikeThroughModel(DATA)); JScrollPane scrollpane = new JScrollPane(table); JFrame frame = new JFrame("StrikeThroughRow"); frame.getContentPane().add(scrollpane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } } class StrikeThroughModel extends DefaultTableModel { public StrikeThroughModel(Object[][] data) { super(new String[]{"Check", "Work Day", "Giant Speak"}, 0); for (int i = 0; i &lt; data.length; i++) { Vector&lt;Object&gt; rowVect = new Vector&lt;Object&gt;(); rowVect.add(data[i][0]); if (data[i].length &gt; 1) { for (int j = 1; j &lt; data[i].length; j++) { rowVect.add(new TextWrapper(data[i][j].toString(), (Boolean)data[i][0])); } } addRow(rowVect); } } @Override public Class&lt;?&gt; getColumnClass(int columnIndex) { if (columnIndex == 0) { return Boolean.class; } return super.getColumnClass(columnIndex); } @Override public void setValueAt(Object value, int row, int column) { if (column == 0) { for (int i = 1; i &lt; getColumnCount(); i++) { TextWrapper textWrapper = (TextWrapper) getValueAt(row, i); textWrapper.setStrikeThrough((Boolean) value); fireTableCellUpdated(row, i); } } super.setValueAt(value, row, column); } } class TextWrapper { private String text; private boolean strikeThrough = false; public TextWrapper(String text) { this.text = text; } public TextWrapper(String text, boolean strikeThrough) { this(text); this.strikeThrough = strikeThrough; } @Override public String toString() { if (strikeThrough) { return "&lt;html&gt;&lt;strike&gt;" + text + "&lt;/html&gt;&lt;/strike&gt;"; } return text; } public void setStrikeThrough(boolean strikeThrough) { this.strikeThrough = strikeThrough; } } </code></pre> <p>I'm betting that there are better solutions including creating a custom renderer for your cells, but the code above offers a quick and dirty fix.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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