[Hibernate]Nome das colunas em uma JTable

2 respostas
nefertiti

Olá a todos!!!

Tenho o seguinte código:

public void PopularTabelaProprietario() {

        
        try{
			
        	String[] colunas = new String[] {"Nome do proprietário","Fazenda"};
        	
        	Session session = HibernateUtility.getSession();
    	
    	    List proprietarios = session.createCriteria(Proprietario.class).list();
    	    
    	    MyTableModel model = new MyTableModel(proprietarios,colunas);
    	    proprietarioExcluirTable.setModel(model); 
    	    proprietarioExcluirTable.setAutoscrolls(false);
            proprietarioExcluirTableScroll.setViewportView(proprietarioExcluirTable);
    		
        }        
			  
	   catch(Exception e){ 
			  
	   }
    }
    
    public class MyTableModel extends AbstractTableModel{
	

	    private static final long serialVersionUID = 1L;
	    private List linhas;
	    private String[] colunas;
	
	    public MyTableModel(List linhas, String[] colunas){
		  
	        
	    	
	    	this.linhas = linhas;
		    this.colunas = colunas;
	   }
	
	   public int getColumnCount(){
		return colunas.length;
	  }
	
	  public int getRowCount(){
		return linhas.size();
	  }
	
	  public Object getValueAt(int rowIndex, int columnIndex){
		Proprietario proprietario = (Proprietario) linhas.get(rowIndex);
		
		 switch(columnIndex) {
			case 0: return proprietario.getNomeProprietario();
			case 1: return proprietario.getFazenda();
			
	     }
	     return null;
	 }

  }

O problema é o seguinte: os nomes das colunas não aparecem na tabela quando eu executo o programa. Aparecem somente os registros do banco, mas não os nomes das colunas que nomeie no String[]. Alguém pode meajudar?

Até mais

Patty

2 Respostas

Luiz_Gustavo

Olá,

Eu costumo usar, para configurar os nomes das colunas, um ColumnModel.

Dê uma olhada NESTE exemplo que eu postei em um outro tópico… talvez possa te ajudar.

[]'s

nefertiti

Olá…obrigada Luiz Gustavo…consegui resolver esse problema!!!

Até mais

Patty

Criado 27 de junho de 2006
Ultima resposta 27 de jun. de 2006
Respostas 2
Participantes 2