Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a JCheckBox in a JTable editable
    primarykey
    data
    text
    <p>I need some help with my JTable. I am writing a program, wich extracts data from a database into a JTable. The first column should be a editable JCheckBox so I am able to work with the checked (true or false) rows and the data.</p> <p>I am using a AbstractTableModel(with class extends AbstractTableModel) and override these five methods:</p> <pre><code> @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return columnIndex == 0; } @Override public Class&lt;?&gt; getColumnClass(int col) { if (col == 0) { return Boolean.class; } return super.getColumnClass(col); } @Override public int getColumnCount() { return header.length; } @Override public int getRowCount() { return data.length; } @Override public Object getValueAt(int row, int col) { return data[row][col]; } </code></pre> <p>To display the JTable I use:</p> <pre><code>JTable table = new JTable(); JScrollPane scrollpane = new JScrollPane(); </code></pre> <p>. . .</p> <pre><code>table = new JTable(data, header); table.setModel(this); scrollpane = new JScrollPane(table); </code></pre> <p>I read the data with a for loop into the data array. The header array I defined. Basically I need the checked rows to send a mail with the right data in it.</p> <p>EDIT:</p> <pre><code>package test; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; public class TestCode extends AbstractTableModel { private static final long serialVersionUID = -7051817393770003705L; String[] header = {"", "header", "header", "header"}; Object[][] data = {{new Boolean(false), "Text", "Text", "Text"}, {new Boolean(false), "Text", "Text", "Text"}, {new Boolean(false), "Text", "Text", "Text"}}; public TestCode() { JFrame frame = new JFrame(); JTable table = new JTable(data, header); table.setModel(this); JScrollPane scrollpane = new JScrollPane(table); frame.add(scrollpane); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); } @Override public boolean isCellEditable(int row, int col) { return col == 0; } @Override public Class&lt;?&gt; getColumnClass(int col) { if (col == 0) { return Boolean.class; } return super.getColumnClass(col); } @Override public int getColumnCount() { return header.length; } @Override public int getRowCount() { return data.length; } @Override public Object getValueAt(int row, int col) { return data[row][col]; } public static void main(String[] args) { TestCode code = new TestCode(); } } </code></pre> <p>This is a short snippet of my code to execute to make it easier for you. I want be able to check the JCheckBoxes at the firt column so I am able to read a true or false boolen from that column.</p> <ul> <li>Thank you for help!</li> </ul>
    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.
 

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