Inserir imagem numa jtable

2 respostas
5
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try{//tratamentos de erros
            DefaultTableModel modelo = new DefaultTableModel(null, new String[] {"Nome", "Funcao", "Funcionamento", "Obs", "Links"});

            Class.forName("com.mysql.jdbc.Driver");//criando uma nova instancia de conexao
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/materialelectrico", "root", "1234"); //criando uma nova conexao indicando um novo caminho
            Statement stmt = con.createStatement(); // objecto comando sql
            String ConsNome = txtpesquisar.getText();


            ResultSet RS = stmt.executeQuery("Select * from material where Nome like = '" + ConsNome + "'");
            while (RS.next()){
                modelo.addRow(new Object[]{RS.getString("Nome"),RS.getString("Foto"),RS.getString("Funcao"),RS.getString("Funcionamento"),RS.getString("Obs"),RS.getString("Links")});
            }
            TabelaPesquisa.setModel(modelo);


            RS.close();
            stmt.close();
            con.close();// fecha conexao com a BD
        }catch (SQLException e){ // trata erros
            JOptionPane.showMessageDialog(this,"Erro com SQL"+e.getMessage());
        }catch (ClassNotFoundException e){
            JOptionPane.showMessageDialog(this,"drive não encontrado");

        }        // TODO add your handling code here:
}                                        

    private void TabelaPesquisaMousePressed(java.awt.event.MouseEvent evt) {                                            
        txtNome.setText(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 0).toString());
 ######       LabelFoto.setIcon(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 1).toString());###########
        txtFuncao.setText(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 2).toString());
        txtFuncionamento.setText(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 3).toString());
        txtObs.setText(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 4).toString());
        txtLinks.setText(TabelaPesquisa.getValueAt(TabelaPesquisa.getSelectedRow(), 5).toString());
eu com este codigo faço uma pesquisa a minha base de dados, depois dessa pesquisa os resultados aparecem numa jtable. e eu tou a conseguir passar tudo que é texto, mas precisava de passar imagem mas nao tou a conseguir? alguem me consegue ajudar?

2 Respostas

paulomn

olha eu nao conheco muito bem jtable, porem para mecher com imagens eu uso o imageicon http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html

5

pessoal, nao tou a conseguir. será que é mais facil por uma jlabel a receber a imagem da base de dados?
se sim como faria?

Criado 30 de junho de 2010
Ultima resposta 30 de jun. de 2010
Respostas 2
Participantes 2