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
| import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class testIHM extends JFrame{
private static final long serialVersionUID = 7856325953273045719L;
private javax.swing.JScrollPane jScrollPane1;
private HandsTableModell2 model;
private javax.swing.JTable jTable1;
private javax.swing.JButton btnRefresh;
public testIHM(){
jScrollPane1 = new javax.swing.JScrollPane();
btnRefresh = new javax.swing.JButton();
setResizable(false);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnRefresh.setText("Filtrer");
btnRefresh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnRafraichirActionPerformed(evt);
}
});
model = new HandsTableModell2(null);
jTable1 = new JTable(model);
jTable1.setAutoCreateRowSorter(true);
jScrollPane1 = new javax.swing.JScrollPane(jTable1);
FlowLayout experimentLayout = new FlowLayout();
final JPanel compsToExperiment = new JPanel();
compsToExperiment.setLayout(experimentLayout);
compsToExperiment.add(jScrollPane1);
compsToExperiment.add(btnRefresh);
add(compsToExperiment);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private void btnRafraichirActionPerformed(java.awt.event.ActionEvent evt) {
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
model.setData(new Object[0][0]);
//model.setData(data);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new testIHM();
}
}
class HandsTableModell2 extends AbstractTableModel {
private static final long serialVersionUID = 3685438063323573991L;
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
private Object[][] data = {};
public HandsTableModell2 (Object[][] donnees){
this.data = donnees;
}
boolean[] canEdit = new boolean [] {
false,false, false, false, false, false
};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
if (data == null) return 0;
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* editable.
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
public void setData(Object[][] tablo) {
data = tablo;
fireTableDataChanged();
}
} |
Partager