1
嗯,這是我第一篇文章。但我有點沮喪,因爲我到處搜索,但沒有任何工作。我有JTable
和代碼正常工作後如果(value.equals("CMAU1294522")
)右下方行。但只有一個單元格是顯示方形框。我點擊了一個特定的行,我希望整行顯示淺灰色(我認爲這是標準)。JTable中的選定行不突出顯示
table = new JTable(sorter) {
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Component comp = super.prepareRenderer(renderer, row, col);
Object value = getModel().getValueAt(row, col);
UIManager.put("Table.editRow", new javax.swing.plaf.ColorUIResource(Color.YELLOW));
if(editingRow ==1){
table.setSelectionBackground(Color.red);
}
if (getSelectedRow() == row) {
table.setSelectionBackground(Color.red);
}
if (value.equals("CMAU1294522")) {
comp.setBackground(Color.red);
} else if (value.equals("PNCT")) {
comp.setBackground(Color.green);
} else if (NewJApplet.contReady.containsKey(value)) {
comp.setBackground(Color.CYAN);
} else if (NewJApplet.badCont.containsKey(value)) {
comp.setBackground(Color.red);
} else {
comp.setBackground(Color.white);
}
return comp;
}
有沒有辦法做到這一點在prepareRenderer
功能我已經有了?
謝謝。但它終於奏效了。我非常感謝你的幫助。 –
@HiTech,很高興幫助,不要忘記「接受」答案,通過點擊複選標記,讓人們知道問題已經解決。 – camickr