I have a JTable that was created in Netbeans's design mode. In my code, I opted for placing the following line of code on startup:
model = new TableModel();
tbShares.setAutoCreateColumnsFromModel(false);
tbShares.setModel(model);
tbShares
is my JTable object.
The JFrame that contains my JTable is shown below:
The first column was set as an Object
type (the other two are Strings), so it can show an image. I have this code that I typed up for it to load an image, but it's not working (the list.add
part, the rest is to give you an insight on how my code is structured). This is the extension of an AbstractTableModel
.
public void addRegister(String status, String name, String clients){
ImageIcon activeStatus = new ImageIcon(CleanSheets.class.getResource("res/img/active.png"));
ImageIcon inactiveStatus = new ImageIcon(CleanSheets.class.getResource("res/img/inactive.png"));
list.add(new Register((status.equals("true") ? activeStatus : inactiveStatus), name, clients));
this.fireTableDataChanged();
}
class Register{
Object status;
String name;
String clients;
public Register(Object status, String name, String clients) {
this.status = status;
this.name = name;
this.clients = clients;
}
}
Supposedly, it grabs the images from the folder I indicated, but then it's just outputting text in that column instead of the actual image. How do I get it to show the correct image? Thank you.
You should re-implement TableCellRenderer
try to read this short article