0
public class TableModelAgendamento extends AbstractTableModel {
int contador = 1;
int qtdFuncionario;
private TOFuncionario[] func = new TOFuncionario[qtdFuncionario];
String coluna[] = new String[qtdFuncionario];
private List<TOItemAgendamento> dados = new ArrayList();
Date hora;
SimpleDateFormat sddf = new SimpleDateFormat("HH:mm:ss");
TOItemAgendamento itemAgenda;
TOItemAgendamento itemAgendamento;
public TableModelAgendamento(TOFuncionario[] funcionario) {
TOItemAgendamento recebeFunc;
TOFuncionario funcio;
qtdFuncionario = funcionario.length;
this.func = funcionario;
for (int i = 1; i < funcionario.length; i++) {
recebeFunc = new TOItemAgendamento();
funcio = new TOFuncionario();
funcio = func[i];
recebeFunc.getFuncionario().setNome(funcio.getNome());
}
zeraTabela();
}
public void zeraTabela() {
try {
Date data = sddf.parse("06:30:00");
Calendar horaInicial = Calendar.getInstance();
horaInicial.setTime(data);
data = sddf.parse("21:00:00");
Calendar horaFinal = Calendar.getInstance();
horaFinal.setTime(data);
while (horaInicial.before(horaFinal)) {
itemAgenda = new TOItemAgendamento();
String horai = sddf.format(horaInicial.getTime());
horaInicial.add(Calendar.MINUTE, 30);
itemAgenda.setHoraMinuto(horai);
itemAgenda.getFuncionario().setNome("");
adicionaLinha(itemAgenda);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void limpar() {
dados = new ArrayList();
fireTableDataChanged();
}
public void setDados(List<TOItemAgendamento> dados) {
this.dados = dados;
fireTableDataChanged();
}
public List<TOItemAgendamento> getDados() {
return dados;
}
public void adicionaLinha(TOItemAgendamento iagendamento) {
dados.add(iagendamento);
fireTableDataChanged();
}
public void removeLinha(int linha) {
dados.remove(linha);
fireTableDataChanged();
}
@Override
public String getColumnName(int coluna) {
TOFuncionario funcio;
for (int i = 1; i < func.length; i++) {
funcio = new TOFuncionario();
funcio = func[i];
return funcio.getNome();
}
return null;
}
@Override
public int getRowCount() {
return dados.size();
}
public TOItemAgendamento getItemCompra(int linha) {
return dados.get(linha);
}
@Override
public int getColumnCount() {
return func.length;
}
@Override
public Object getValueAt(int linha, int coluna) {
TOItemAgendamento itemAgendamento = dados.get(linha);
int i = 1;
for(int cont = 0; cont <= qtdFuncionario; cont++){
System.out.println("get valueat ");
switch (coluna) {
case 0:
return dados.get(linha).getHoraMinuto();
case Integer.SIZE:
return dados.get(linha).getHoraMinuto();
}
}
return null;
}
@Override
public void setValueAt(Object valor, int linha, int coluna) {
TOItemAgendamento itemAgendamento = dados.get(linha);
switch (coluna) {
case 0:
break;
case 1:
dados.get(linha).getFuncionario().setNome((String) valor);
break;
case 2:
dados.get(linha).getFuncionario().setNome((String) valor);
break;
case 3:
dados.get(linha).getFuncionario().setNome((String) valor);
break;
default:
JOptionPane.showMessageDialog(null, "Erro no TableModelItemCompra, coluna não esperada em setValueAt.");
}
fireTableDataChanged();
}
What is the question?
– mgibsonbr
I am receiving as parameter in my constructor method an object vector, I need getColumnName to return the employee name of each object of this vector.
– Ana
I still don’t understand what the question is (your code doesn’t work? it works, but it doesn’t do what it wants? doesn’t know what code to put? etc), but I remember a long time ago I did something like this. You call
fireTableDataChangedevery time the lines change, right? When the columns change, you need to shootfireTableStructureChanged. Try calling this method wheneverfuncchange, this should make Java recalculate all columns.– mgibsonbr
@Override public String getColumnName(int column) { Function function; for (int i = 1; i < func.length; i++) { function = new Function(); function = function[i]; function function.getName(); Return null; } // In this method I need to take the name of the employees to put in the columns, but when I give a Return getName inside the for it arrow all the columns with the same name. Got it ?
– Ana
Now I do! As you had only posted the code (and a large code on top of that) but did not say what I wanted I had no idea what the problem was... But now it’s clear, see my answer below. P.S. If you can, I suggest [Edit] the question by putting this information.
– mgibsonbr