简体   繁体   中英

My JTable is still editable when double-clicking after return isEditable to false?

Here is my code to update my table:

private void UpdateTable() {
    String sql = "SELECT * FROM product";

    pst = conn.prepareStatement(sql);
    rs = pst.executeQuery();

    summaryproductTable.setModel(DbUtils.resultSetToTableModel(rs));
}

And this is the code that is generated by Netbeans(7.3.1), I've added the isEditable because I'm following the instruction that I found here in stackoverflow:

summaryproductTable = new javax.swing.JTable();

summaryproductTable.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N

summaryproductTable.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null},
        {null, null, null, null, null, null, null, null, null}
    },
    new String [] {
        "type", "materialcode", "serialnumber", "status", "careof", "date", "name",        "accountnumber", "contactnumber"
    }
)
{public boolean isCellEditable(int row, int column){return false;}}
);



summaryproductTable.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
        summaryproductTableMouseClicked(evt);
    }
});

jScrollPane1.setViewportView(summaryproductTable);

*I just noticed through trial and error that the JTable is not editable but when you called the UpdateTable() method it become editable again.

在NetBeans中,右键单击表->属性->复选框中的“可编辑”,以使其未选择“简单...”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM