我正在研究一点JTable
。当前看起来像这样JTable
。
如您所见,它继续使用最后一种颜色绘画,由于某种原因,我无法修复它。
String[] columnNames = { "Spieler", "Verfügbare Truppen", "besetzte Länder" };
Object[][] data = { { Player1.getName(), Player1.troopscore, Player1.countryscore },
{ Player2.getName(), Player2.troopscore, Player2.countryscore },
{ Player3.getName(), Player3.troopscore, Player3.countryscore },
{ Player4.getName(), Player4.troopscore, Player4.countryscore },
{ Player5.getName(), Player5.troopscore, Player5.countryscore },
{ Player6.getName(), Player6.troopscore, Player6.countryscore },
};
table = new JTable(data, columnNames) {
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Component comp = super.prepareRenderer(renderer, row, col);
for (int i = 0; i < playerlist.size(); i++) {
Object value = getModel().getValueAt(i, 0);
{
if (row == i && col == 0 && value == playerlist.get(i).getName()) {
{
System.out.println(value);
comp.setBackground(playerlist.get(i).player_color);
}
}
}
}
return comp;
}
};
感谢您的帮助:)