0

How to make cells of JTable non-editable, but selectable. Below code is Jtable column value ........

  DefaultTableModel dtmPrefix = new DefaultTableModel();  
     dtmPrefix.addColumn("Code");  
    dtmPrefix.addColumn("Name"); 
     dtmPrefix.addColumn("Quantity"); 
     dtmPrefix.addColumn("Price");  
    try { 
       Connection conn= Dbutil.getlocalConnection();
        String queryPrefix = "SELECT * FROM product_master"; 
        st = conn.createStatement(); 
        rs = st.executeQuery(queryPrefix);  
        while(rs.next()){  
            dtmPrefix.addRow(new Object[]{  
               rs.getString(2) ,
              rs.getString(3), 
                 rs.getString(5) ,
              rs.getString(6),  
            }); 
            jTable1.setModel(dtmPrefix);   
             jTable1.setEditingColumn(false);
          jTable1.editingCanceled(e);
        } 
    } catch (  Exception ex ) { 
    } 
karthi N
  • 21
  • 8

1 Answers1

2

Override the isCellEditable(...) method of your DefaultTableModel to return false.

jTable1.setEditingColumn(false);
jTable1.editingCanceled(e);

The above statements don't do anything. They basicaly just change a property of the table to say that no cedll is currently being edited, but it doesn't prevent a cell from being edited. So you can get rid of those statements.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • plz exaplain clearly with code – karthi N Mar 15 '16 at 04:17
  • 1
    It is explained clearly. What part about the solution do you not understand? Clearly explain your confusion with the suggestion. Post your attempt at overriding the method and we can help fix it if it still doesn't work, but we are not here to write the code for you. – camickr Mar 15 '16 at 05:15