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
| public class Test1 extends JFrame {
public JTable table;
JPanel pann = new JPanel(new GridLayout(0,1));
JPanel gestion = new JPanel(new GridLayout(1,3));
public Test1() {
super();
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton Ajouter = new JButton("Ajouter");
JButton Supprimer = new JButton("Supprimer");
JButton Valider = new JButton("Valider");
pann.setPreferredSize(new Dimension(500, 500));
table = new JTable ( new TableModel(6,3));
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
pann.add(scrollPane);
getContentPane().add("Center",pann);
gestion.add(Ajouter);
gestion.add(Supprimer);
gestion.add(Valider);
setSize(600,400);
getContentPane().add("South",gestion);
Ajouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
ajouterActionPerformed(e);
}
});
}
public void ajouterActionPerformed(ActionEvent e){
String [] data = new String [table.getColumnCount()];
}
public static void main(String[] args)
{
Test1 test = new Test1();
test.pack();
test.setVisible(true);
}
//////////////////DEFINITION DU JTABLE /////////////
class TableModel extends AbstractTableModel
{
private String[] columnNames={"toto","tutu","titi"};
private Object[][] data;
public TableModel (int r , int c )
{
data = new Object[r][c];
columnNames = new String[c];
for ( int i = 0 ; i < r ; i++ )
{
for ( int j = 0 ; j < c ; j++ )
{
data[i][j] =i;
}
}
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex][columnIndex];
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col)
{
return true;
}
public void setValueAt(Object value, int row, int col)
{
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
} |
Partager