Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single click to edit a JTable Cell

Tags:

java

swing

jtable

currently the JTable cell is selected on first click, and on the second one it is edited.

Is it possible to directly edit it on the first click?

like image 239
Akash Avatar asked Sep 12 '11 11:09

Akash


People also ask

How do you make a JTable cell editable?

jTableAssignments = new javax. swing. JTable() { public boolean isCellEditable(int rowIndex, int colIndex) { return editable; }};

How do I highlight a cell in JTable?

You can select cells by simulating clicks. To simulate clicks on JTable cells, you can use the ClickCell , ClickCellR , DblClickCell and similar actions of the JTable object. All of these actions have parameters that specify the row and the column that contain the needed cell.


1 Answers

In the DefaultCellEditor api there is a method named setClickCountToStart

    DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField());
    singleclick.setClickCountToStart(1);

    //set the editor as default on every column
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.setDefaultEditor(table.getColumnClass(i), singleclick);
    } 
like image 102
Neifen Avatar answered Oct 21 '22 07:10

Neifen