Ok funziona...sempre se importasse a qualcuno
Metto il codice:
codice:
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component precotto = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); int rowSel=table.getSelectedRow(); int colSel=table.getSelectedColumn(); int elemSel=(rowSel*16)+(colSel-1); int thisElem=(row*16)+(column-1); //Se è selezionata una cella if(colSel>=0 && rowSel>=0){ //Se la cella selezionata è dell'intestazione [0-511] if(elemSel<512){ if(thisElem<512 && column!=17 && column!=0){ precotto.setForeground(table.getSelectionForeground()); precotto.setBackground(table.getSelectionBackground()); } else{ precotto.setForeground(Color.BLACK); precotto.setBackground(Color.WHITE); } } //Se la cella selezionata è un record [512-...] else{ int thisRecord=(thisElem-512)/129; int selRecord=(elemSel-512)/129; if(thisRecord==selRecord && column!=17 && column!=0 && thisElem>=512){ precotto.setForeground(table.getSelectionForeground()); precotto.setBackground(table.getSelectionBackground()); } else{ precotto.setForeground(Color.BLACK); precotto.setBackground(Color.WHITE); } } } else{ precotto.setForeground(Color.BLACK); precotto.setBackground(Color.WHITE); } if(column==0){ setHorizontalAlignment(RIGHT); precotto.setForeground(Color.BLACK); precotto.setBackground(Color.GREEN); } else if(column==17) setHorizontalAlignment(LEFT); else setHorizontalAlignment(CENTER); return this; }
Usando l'ogetto table del metodo posso risalire alla cella selezionata e controllare se quella corrente (quella che viene ritornata dal metodo) fa parte dello stesso record oppure no. In caso affermativo la evidenzio altrimenti no.