Creating Persistant Reference To JTable Data
<p>I am trying to create a JTable in IntelliJ with two columns: one is a checkbox, and the other is a string. A user can add an arbitrary string to the table by pressing a JButton, and each time the button is pressed a new row is added to the table where the first column is a checkbox and the second is the arbitrary string. This can be done any number of times adding any number of rows to the table. By clicking on the checkboxes and pressing a remove button, that row is removed from the table. This entire process works fine, but is not what I am having trouble with.</p>

<p>Every time the user presses the button adding a string to the table, I want to add that string to a consistent object/container. So at initialization the object is empty,</p>

<pre><code>Object[][] tableData;
</code></pre>

<p>but when the button is pressed the object now contains the "checkbox" represented by a boolean, and the string.</p>

<pre><code>Object[][] tableData = {
    {false, "String"}
}
</code></pre>

<p>And this can go for awhile.</p>

<pre><code>Object[][] tableData = {
    {false, "String"},
    {false, "String"},
    {false, "String"},
    {false, "String"},
    {false, "String"},
    {false, "String"}
}
</code></pre>

<p>And if any of the boolean values get changed to true (via the checkbox), and the remove button is pressed, then that specific "row" or part of the object gets deleted. How would I go about creating this object or container and maintain it? Is there a better way of doing this without an object?</p>

<p>A simple overview of what I have right now is below.</p>

<pre><code>String colNames = {" ", "String"};
DefaultTableModel tableModel = new DefaultTableModel(colNames, 0);

importTable = new JTable(tableModel) {
    @Override
    public Class getColumnClass(int column) {
        switch(column) {
            case 0:
                return Boolean.class;
            default:
                return String.class;
        }
    }
};

importButton.addActionListener(new ActionListener() {
    public void actionPerofrmed(ActionEvent e) {
        Object[][] newData = {
            {false, "String"}
        };
        tableModel.addRow(newData[0]);
    }
});

removeButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        for (int i = 0; i &lt; tableModel.getRowCount(); i++) {
            Boolean checked = (Boolean) tableModel.getValueAt(i, 0);
            if (checked) {
                tableModel.removeRow(i);
                i--;
            }
        }
    }
});
</code></pre>