0

I've been trying to display a JTable and have been getting strange artifacts.

I have a class that extends AbstractTableModel. I'm not sure why I'm getting these artifacts. How do I get JTable to display correctly?

Bad Table

Below is my TableModel

public class AllScansModel extends AbstractTableModel {

private List<WasScan> wasScans;
private String[] columns = new String[] { "Name", "Type", "Profile", "Date", "Status" };

public AllScansModel(List<WasScan> wasScans) {
    this.wasScans = wasScans;
}

@Override
public int getRowCount() {
    return wasScans.size();
}

@Override
public int getColumnCount() {
    return columns.length;
}

public void setValueAt(int rowIndex, WasScan wasScan) {
    wasScans.set(rowIndex, wasScan);
    fireTableRowsUpdated(rowIndex, rowIndex);
}

public void addValue(WasScan wasScan){
    wasScans.add(wasScan);
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    WasScan scan = wasScans.get(rowIndex);
    switch (columnIndex) {
    case 0:
        return scan.getName().getValue();
    case 1:
        return scan.getType().toString();
    case 2:
        return scan.getProfile().getName().toString();
    case 3:
        return scan.getEndScanDate().toString();
    case 4:
        return scan.getStatus().toString();
    }
    return null;
}

@Override
public String getColumnName(int column) {
    return columns[column];
}

public void updateTable(List<WasScan> wasScans) {
    this.wasScans = wasScans;
    fireTableDataChanged();
}
}
Reversial
  • 1
  • 1
  • You have a custom painting issue. Have you overridden `paint`, `paintComponent`, `update` or any other `paint` method? Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Jul 07 '15 at 00:03
  • 1
    *"I have a class that extends AbstractTableModel."* ..why? Or rather, why not extend a `DefaultTableModel` which already does most of what is required (correctly)? – Andrew Thompson Jul 07 '15 at 00:04
  • See [Detection/fix for the hanging close bracket of a code block](http://meta.stackexchange.com/q/251795/155831) for a problem I could no longer be bothered fixing. – Andrew Thompson Jul 07 '15 at 00:04

0 Answers0