簡體   English   中英

如何從JTable單元格中檢索數據,而不是從表格模型中檢索數據?

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

我有這個渲染器,它改變了JTable單元格的值。

@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;
}

在表的數據模型中,第1行第2列中的數據為“ - ”
在JTable GUI中,第1行第2列的數據是“錯誤”

此代碼在數據模型中打印值:“ - ”。

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

有沒有簡單的方法來檢索值“錯誤”?

我假設您的渲染器擴展了JLabel

((JLabel)table.getCellRenderer(row, column)
.getTableCellRendererComponent(pass all the params here)).getText();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM