How to avoid the doubleclick edition of Mouseclicked on a jTable in java?

0

I have a jTable and I want that at the moment of double clicking, I do not edit the table since I have a part of the code in which it is valid that only numbers can be entered and it does, but when I double click on the table allows me to put letters. I have this part of code:

 private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     

 if (evt.getClickCount() == 1) {

     System.out.println("Se ha hecho un click");            
    }
    if (evt.getClickCount() == 2) {
        System.out.println("Se ha hecho un click");

    }

// TODO add your handling code here:
}
    
asked by Andres Orellana 17.07.2017 в 23:40
source

1 answer

0

You must place the column as not editable, at the time of setting the model of your table:

tbTransacciones.setModel(new DefaultTableModel(
            new Object[][] {},
            new String[] {
                    "COLUMNA1", "COLUMNA2", "COLUMNA3", "COLUMNA4", "COLUMNA5"
            }) {
            @SuppressWarnings("rawtypes")
            Class[] columnTypes = new Class[] {
                Integer.class, String.class, Integer.class, Integer.class, Integer.class
            };
            @SuppressWarnings({ "unchecked", "rawtypes" })
            public Class getColumnClass(int columnIndex) {
                return columnTypes[columnIndex];
            }
            boolean[] columnEditables = new boolean[] {
                false, false, false, false, false
            };
            public boolean isCellEditable(int row, int column) {
                return columnEditables[column];
            }
        });
    
answered by 18.07.2017 в 17:34