开发者

AbstractTableModel setValueAt not firing upon Jbutton Click

开发者 https://www.devze.com 2023-02-22 18:14 出处:网络
I have a custom TableModel that extends the AbstractTableModel. public class IndicatorPropertyTableModel extends AbstractTableModel

I have a custom TableModel that extends the AbstractTableModel.

public class IndicatorPropertyTableModel extends AbstractTableModel

The setValueAt function I wrote fires appropriately in cases when you type a new value into the editable cell and then move on to another cell. The problem I am having is that for the last editable cell the user will immediately click a JButton to continue. This does not trigger the setValueAt function thus not saving the data. Is there a good way to ensure that this value is always stored when a user immediately hits a button after editing a cell? setValueAt function below for reference if needed.

public void setValueAt(Object value, int row, int col) {
    if (value == null)
        return;
    if开发者_如何转开发 (col == 0) {
        //this.indicatorArguments[row].setIsSelected(value);
    } else if (col == 2) {
        this.indicatorArguments[row].setValue(value);
    }
    this.fireTableCellUpdated(row, col);
}

Thanks for any help you can provide.


I assume that your button is outside the table.

In the event listener or action of your button you would need a reference to the table. This table you could then ask whether isEditing returns true. Then you would get the current editor and after validating the last input value either call stopCellEditing to commit the value or cancelCellEditing to undo the value.

In short:

if(table.isEditing()){
  table.getCellEditor().stopCellEditing();
}

would always commit not yet entered values.


Checking if the table is editing requires you to add code to all buttons on your GUI.

You may be able to use a simple one line solution that avoids this. Check out Table Stop Editing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号