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
|
public class Tmodel extends AbstractTableModel{
String[] columnNames = null ;
Object[][] data = null ;
int edit_limite = 0 ;
public Tmodel(int l, int c,String[] header, int ec)
{
data = new Object[l][c] ;
columnNames = header ;
edit_limite = ec ;
}
public int getColumnCount(){
return columnNames.length;
}
public Object getValueAt(int l, int c){
return data[l][c] ;
}
public void setValueAt(Object val ,int l, int c){
data[l][c]= val ;
}
public int getRowCount(){
return data.length ;
}
public String getColumnName(int c){
return columnNames[c] ;
}
public Class getColumnClass(int c){
try{
return getValueAt(0,c).getClass();
}
catch (Exception ex){
return "".getClass() ;
}
}
public boolean isCellEditable(int r, int c){
if(c<edit_limite)
return false ;
else
return true ;
}
}
La classe fenetre :
public class SimautoCadre extends JFrame{
Tmodel TablePerso = null ;
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 = null ;
private Border border1;
JButton jButton1 = new JButton();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
AutoSizeCellClass auto = new AutoSizeCellClass();
public SimautoCadre()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception{
contentPane = (JPanel) this.getContentPane();
border1 = BorderFactory.createMatteBorder(6,6,6,6,Color.orange);
titledBorder1 = new TitledBorder("");
contentPane.setLayout(null);
this.setResizable(false);
this.setSize(new Dimension(1000, 800));
this.setTitle("Résultats Simulation Automatique");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(142, 253, 480, 155));
jPanel1.setLayout(null);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setAutoscrolls(true);
jScrollPane1.setBorder(BorderFactory.createEtchedBorder());
jScrollPane1.setBounds(new Rectangle(0, 0, 1020, 500));
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
contentPane.add(jScrollPane1, null);
contentPane.add(jButton1, null);
contentPane.add(jPanel1, null);
// initialiser notre modèle de table
String[] colh = {"Sim simple/complète","Armoires KO","Nombre Armoires KO",puissancearmstock.nomarmoire[0]} ;
TablePerso = new Tmodel(BarreSimAuto.nbcas,4,colh,BarreSimAuto.nbcas);
// la table basée sur notre modèle de table
jTable1 = new JTable(TablePerso);
jTable1.setGridColor(Color.green);
jTable1.setFont(new java.awt.Font("SansSerif", 1, 16));
jScrollPane1.getViewport().add(jTable1, null);
auto.autoSizeCells(jTable1,true,true);
} |
Partager