Olá pessoal,
Criei um TableCellRenderer que extende a classe DefaultTableCellRenderer.
Quando o método getTableCellRendererComponent da minha classe é invocado, primeiramente chamo o getTableCellRendererComponent da classe DefaultTableCellRenderer, o qual por sua vez verifica se está sendo realizado um drop. Se true, obtém-se os Color do foreground e background, conforme abaixo:
//Classe javax.swing.table.DefaultTableCellRenderer.
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color fg = null;
Color bg = null;
JTable.DropLocation dropLocation = table.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsertRow()
&& !dropLocation.isInsertColumn()
&& dropLocation.getRow() == row
&& dropLocation.getColumn() == column) {
fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground"); //O problema está aqui
bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground"); //O problema está aqui
isSelected = true;
}
//(...)
}
A minha classe possui a seguinte implementação do método getTableCellRendererComponent:
//Minha classe.
@Override
public java.awt.Component getTableCellRendererComponent( final javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
final Integer line = row + 1;
final String text;
if( this.format != null ){
text = this.format.format( line );
}
else{
text = line.toString();
}
super.setText( text );
super.setHorizontalAlignment( this.alignmentHorizontal );
return this;
}//Fim do metodo.
Como implementei um DnD, quando o usuário está realizando um dragged, a célula onde está o mouse deveria ficar com a cor de uma linha selecionada, mas, por algum motivo que eu desconheço, não está.
Sendo assim, preciso saber porque a chamada DefaultLookup.getColor(this, ui, “Table.dropCellForeground”) e DefaultLookup.getColor(this, ui, “Table.dropCellBackground”) está retornando null,quando deveria retornar a cor de um célula selecionada.