ListSelectionMode.SINGLE_SELECTION não funciona no JTable
Criei um construtor para mudar a cor do texto na tabela conforme o que tiver na coluna 5, o problema é que eu não consigo a seleção da linha inteira, apenas de uma célula.
Tentei de várias formas sem sucesso, algumas estão comentadas.
Segue o código:
Tentei de várias formas sem sucesso, algumas estão comentadas.
Segue o código:
private void cor(){
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
//table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
//Linhas responsáveis pela cor da tabela----------
Color cor = Color.WHITE;
Object texto = table.getValueAt(row, 5);
if("Ativo".equals(texto.toString())){
cor = new Color(0,88,51);
}if("Pendente".equals(texto.toString())){
cor = Color.ORANGE;
}if("Bloqueado".equals(texto.toString())){
cor = Color.GRAY;
}if("Cancelado".equals(texto.toString())){
cor = Color.RED;
}
label.setForeground(cor);
table.setOpaque(false);
((DefaultTableCellRenderer)table.getDefaultRenderer(Object.class)).setOpaque(false);
table.getTableHeader().setReorderingAllowed(false);
table.setCellSelectionEnabled(true);
table.setSelectionBackground(null);
//-----------------------------------------------
//table.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
return label;
}
});
}
Leandro Matos
Curtidas 0