martes, 30 de octubre de 2007

BItem

public class BItem{
public String Codigo;
public String Descripcion;
public BItem(String c ,String d ){
Codigo = c;
Descripcion = d;
}
public String toString(){
return Descripcion;
}
}

lunes, 22 de octubre de 2007

JTable - AbstractTableModel

import javax.swing.table.AbstractTableModel;
public class miModeloTabla extends AbstractTableModel{
Object[][] datos={
{"001","Soto","Quispe","Cesar",new Integer(12), new Boolean(true)},
{"002","Rivas","Quintana","Carlos",new Integer(12), new Boolean(true)}};
String[] encabezado={"Codigo","Paterno","Materno","Nombre","Nota","Casado"};
public int getColumnCount() {
return encabezado.length;
}
public int getRowCount() {
return datos.length;
}
public Object getValueAt(int f, int c) {
return datos[f][c];
}
public String getColumnName(int c){
return encabezado[c];
}
public Class getColumnClass(int c){
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int f, int c){
return true;
}
public void setValueAt(Object value,int f,int c){
datos[f][c]=value;
}
}

------------------------------------------------------
TableColumn sportColumn = table.getColumnModel().getColumn(2);
...
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Chasing toddlers");
comboBox.addItem("Speed reading");
comboBox.addItem("Teaching high school");
comboBox.addItem("None");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));