How to retrieve the data from the JTable cell and not the data from the table model?

StackOverflow https://stackoverflow.com/questions/17832375

  •  04-06-2022
  •  | 
  •  

Вопрос

I have this renderer that changes the value of JTable cell.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    String label = value.toString();
    if(label.equals("-")
        label = "error";
    setValue(label);

    return this;
}

In the table's data model, data in row 1, column 2 is "-"
In the JTable GUI, data in at row 1, column 2 is "error"

This code prints the value in data model: "-".

System.out.println(table.getValueAt(1, 2).toString());

Is there any simple way to retrieve the value "error"?

Это было полезно?

Решение

I assume your renderer extends JLabel

((JLabel)table.getCellRenderer(row, column)
.getTableCellRendererComponent(pass all the params here)).getText();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top