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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
//initialisation de ma fenetre graphique
public void init()
{
Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("images/myotis.png"));
setIconImage(icon);
initComponents();
// Centrage de la fenetre
Toolkit tk = Toolkit.getDefaultToolkit() ;
Dimension d = tk.getScreenSize() ; // resolution de l'ecran
this.hEcran = (int)(d.getHeight()); // hauteur de l'ecran
this.lEcran = (int)(d.getWidth()); // largeur de l'ecran
setLocation((lEcran-this.getWidth())/2,(hEcran-this.getHeight())/2);
initJTable();
Object[] o = new Object[5];
for(int i=0 ; i<5 ; i++)
o[i] = ""+i ;
tm.addLigne(o);
tm.addLigne(o);
detection.setModel(tm );
this.validate();
this.setVisible(true);
}
// Methode d'initialisation de la JTable des voies
private void initJTable()
{
this.tm = new TableModele();
DefaultTableCellRenderer dr = new DefaultTableCellRenderer();
dr.setHorizontalAlignment(SwingConstants.CENTER);
this.detection.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
this.detection.setModel(tm);
for(int i=0;i<5;i++)
{
TableColumn col = this.detection.getColumnModel().getColumn(i);
col.setCellRenderer(dr);
}
}
// Classe representant les elements du tableau
public class TableModele extends DefaultTableModel
{
private Object[][] data ;
private Object[] colonnesNom ;
private boolean ALLOW_ROW_SELECTION = true;
private int row_count = 1 ;
public TableModele()
{
this.colonnesNom = new Object[5];
this.data = new Object[row_count][5];
init();
}
public void init()
{
// Initialisation des titres
this.colonnesNom[0] = new String("Heure");
this.colonnesNom[1] = new String("Ratio Detect.");
this.colonnesNom[2] = new String("Ratio Max.");
this.colonnesNom[3] = new String("Max Ampl.");
this.colonnesNom[4] = new String("Count");
// Initialisation des cellules
detection.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
if (ALLOW_ROW_SELECTION)
{ // true by default
ListSelectionModel rowSM = detection.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty())
{
System.out.println("Lignes selectionnables");
}
else
{
int selectedRow = lsm.getMinSelectionIndex();
System.out.println("ligne " + selectedRow + " est selectionnee");
}
}
});
}
else
{
detection.setRowSelectionAllowed(false);
}
super.setDataVector(this.data,this.colonnesNom);
}
public void addLigne(Object[] o)
{
super.addRow(o);
}
public Object getValueAt(int ligne, int col){return data[ligne][col];}
public String getColumnName(int col){return (String)colonnesNom[col];}
public void setValueAt(Object value, int ligne, int col)
{
this.data[ligne][col] = value ;
fireTableCellUpdated(ligne, col);
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col)
{
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
return false ;
}
} |