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
| public class Analyse extends JFrame
{
private JTable jTable = null;
public Analyse {
super();
initialize();
//... je passe sinon ca devient illisible avec tout ce que j'ai mis
private JPanel getJContentPane(){
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(0, 204, 255));
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(39, 42, 747, 247));
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
// Le model de table
public void setModel(TableModel model) {
jTable.setModel(model);
}
private JTable getJTable() {
if (jTable == null)
{
jTable = new JTable();
DefaultTableModel defaultModel = new DefaultTableModel(columsNames,0)
{
public Class getColumnClass(int columnIndex)
{
jTable.getColumnModel().getColumn(0).setPreferredWidth(300);
if(columnIndex == 1 || columnIndex == 2 || columnIndex == 3 || columnIndex == 4) {
return Integer.class;
} else {
return super.getColumnClass(columnIndex);
}
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
// rendre non editable la jtable
return columnIndex >= 10;
}
};
setModel(defaultModel);
return jTable;
}
// J'ajoute à la fin du fichier ceci:
public Component getTableCellRendererComponent(
JTable table, Object color,
boolean isSelected, boolean hasFocus,
int row, int col) {
Color newColor = (Color)color;
setBackground(newColor);
JLabel cellule = new JLabel();
if (col == 2)
{
cellule.setOpaque(true);
cellule.setBackground(Color.blue);
}
return cellule;
}
} |
Partager