1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| /*
* NewClass.java
*
* Created on 24. octobre 2006, 14:08
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package dmind.ihm;
import dmind.gestion_questionnaire.Titre;
import ihm.Ihm_creation_questionnaire;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
/**
* Classe pour rendre (montrer) différentes cellules dans un JTable, Paramétrée pour les besoins du projet
* @author XXX
*/
public class ColorTableCellRenderer extends DefaultTableCellRenderer {
/**
* Méthode permettant de rendre le modèle de cellule à appliquer
* @param table La jTable concernée
* @param value La valeur à assigner à la cellule à la position [ligne, colonne]
* @param isSelected Vrai si la cellule est selectionnée
* @param hasFocus Vrai si la cellule est focussée
* @param row La ligne de la cellule à rendre
* @param column La colonne de la cellule à rendre
* @return Le modèle de cellule
*/
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row) instanceof Titre) {
if(((Titre)Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row)).getNiveauTitre()==1){
this.setBackground(new Color(101, 114, 235));
this.setForeground(Color.WHITE);
Font f = new Font("Sheriff", Font.BOLD+Font.ITALIC, 15);
this.setFont(f);
} else if(((Titre)Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row)).getNiveauTitre()==2){
this.setBackground(new Color(142, 151, 235));
this.setForeground(Color.WHITE);
Font f = new Font("Sheriff", Font.BOLD, 12);
this.setFont(f);
} else if(((Titre)Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row)).getNiveauTitre()==3){
this.setBackground(new Color(178, 178, 241));
this.setForeground(Color.WHITE);
Font f = new Font("Sheriff", Font.ITALIC, 12);
this.setFont(f);
} else if(((Titre)Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row)).getNiveauTitre()==3){
this.setBackground(new Color(101, 114, 235));
this.setForeground(Color.BLACK);
} else if(((Titre)Ihm_creation_questionnaire.leTypeQuestionnaire.getListeQuestionsTitres().get(row)).getNiveauTitre()==3){
this.setBackground(new Color(101, 114, 235));
this.setForeground(Color.BLACK);
} else{
if(Ihm_creation_questionnaire.jTableau.getSelectedRow()==row){
this.setBackground( new Color(184, 207, 229));
this.setForeground(Color.BLACK);
}else{
this.setBackground(Color.WHITE);
this.setForeground(Color.BLACK);
}
}
}else{
if(Ihm_creation_questionnaire.jTableau.getSelectedRow()==row)
this.setBackground( new Color(184, 207, 229));
else{
this.setBackground(Color.WHITE);
this.setForeground(Color.BLACK);
}
}
return (JLabel)this;
}
} |
Partager