Fiz um sistema de cadastramento de tarefas, e queria alterar o a cor de uma linha JTable de acordo com as “Prioridades”, achei este método, que aparentemente funcionaria , más está dando erro quando eu faço o “CLASS” receber um valor, alguem pode me ajudar por favor.
No seu fonte CLASS é final então você não pode atribuir outro valor à ela.
Neste link tem um exemplo de como criar um renderizador personalizado.
G
Gustavoo
Obrigado, vou estudar e tentar implementar na minha jTable
jallisson_jallis1 like
abaixo exemplo bom
/* * To change this template, choose Tools | Templates * and open the template in the editor. * codigo original: http://pt.stackoverflow.com/questions/4591/como-colorir-linhas-espec%C3%ADficas-de-uma-jtable * codigo original: http://stackoverflow.com/questions/5557485/why-does-my-java-custom-cell-renderer-not-show-highlighting-when-the-row-cell-is */packagesip.util;importjava.awt.Color;importjava.awt.Component;importjavax.swing.JLabel;importjavax.swing.JTable;importjavax.swing.table.DefaultTableCellRenderer;/** * * @author Alessandra */publicclassColorirTabelaTramitacaoextendsDefaultTableCellRenderer{/** * */privatestaticfinallongserialVersionUID=1L;publicstaticfinalfloatR=0.9f;publicstaticfinalfloatG=0.5f;publicstaticfinalfloatB=0.8f;@OverridepublicComponentgetTableCellRendererComponent(JTabletable,Objectvalue,booleanisSelected,booleanhasFocus,introw,intcolumn){super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);//203,216,227//Color c = new Color(203,216,227);Colorc=Color.WHITE;Objecttext=table.getValueAt(row,3);Objecttext2=table.getValueAt(row,10);if(text!=null&&"LICENÇA EMITIDA".equals(text.toString())){// RGBc=newColor(126,195,255);}if(text!=null&&"DESARQUIVADO".equals(text.toString())){c=Color.GREEN;}if(text!=null&&"ARQUIVADO".equals(text.toString())){c=Color.RED;}if(text2!=null){c=Color.YELLOW;}setBackground(c);if(isSelected){//setForeground(Color.BLUE);setBackground(table.getSelectionBackground());}returnthis;}}
jallisson_jallis1 like
O uso da classe abaixo, utilizar até a terceira linha de código.