Java, change a cell content as a function of another cell in the same row

后端 未结 2 904
青春惊慌失措
青春惊慌失措 2020-11-27 22:35

I need some help for my problem. I have a table with e.g. a double column and a string column. If the value in the double column is negativ, the string should be \"negativ\"

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 23:21

    You do indeed have access to the TableModel, if I'm not mistaken, through TableModelEvent.getSource().

    Just to provide a basic example (mostly because the one sentance answer hardly seems like much of an answer):

    TableModel model = (TableModel)te.getSource();
    Double number = model.getValueAt(te.firstRow, 0);
    model.setValueAt(((number < 0) ? "negativ":"positiv"), te.firstRow, 1);
    

提交回复
热议问题