Ola, pessoal.
Sou novo com java, gostaria de saber como faço para pegar um dado do banco convertendo de Int para String,
A situação é a seguinte, enviei um dado para o banco ele é um boolean um jCheckbox, no banco guarda um Int, agora preciso pegar esse Int mostrando como String em uma Jtable.
Alguem tem alguma ideia de como fazer isso?
Passar um campo Int para String java swing
16 Respostas
O mais simples:
int x = 10;
String sx = x + "";
A classe String possui funções para essas ‘conversões’. Nesse caso específico:
String.valueOf(int valor);
Fonte: Doc Oracle.
Pessoa aqui minha tela, nela faço a inserção dos dados, tem esse Habilitar que seria o boolean, ele passo para o banco como Int, fazendo a conversão, agora quero pegar ele nessa tabela na coluna Statis Evento seria para mostra se 0 = Habilitado, se 1 = Desabilitado e não o 0 ou 1 como mostra hoje, isso que não sei como fazer, desde já agradeço a ajuda de todos!

String texto = valor == 0 ? "Habilitado" : "Desabilitado";
Esse trecho devo colocar onde?
No local onde você quiser converter a variável int valor para String.
Essas são minhas classes
package table;
import modelo.bean.Evento;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
public class EventosTableModel extends AbstractTableModel{
public static final int COL_CODIGO_EVENTO = 0;
public static final int COL_DESCRICAO_EVENTO = 1;
public static final int COL_HORA_INICIAL_EVENTO = 2;
public static final int COL_HORA_FINAL_EVENTO = 3;
public static final int COL_STATUS_EVENTO = 4;
public ArrayList<Evento> lista;
public EventosTableModel(ArrayList<Evento>l){
lista = new ArrayList<Evento>(l);
}
@Override
public int getRowCount() {
return lista.size();
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public Object getValueAt(int linhas, int colunas) {
Evento evento = lista.get(linhas);
if(colunas == COL_CODIGO_EVENTO) return evento.getIdEvento();
if(colunas == COL_DESCRICAO_EVENTO) return evento.getDescricao();
if(colunas == COL_HORA_INICIAL_EVENTO) return evento.getDtini();
if(colunas == COL_HORA_FINAL_EVENTO) return evento.getDtfin();
//String texto = evento.getStatus() == 0 ? “Habilitado” : “Desabilitado”;
if(colunas == COL_STATUS_EVENTO) return evento.getStatus();
return "";
}
@Override
public String getColumnName(int colunas){
if(colunas == COL_CODIGO_EVENTO)return "Código";
if(colunas == COL_DESCRICAO_EVENTO)return "Descrição";
if(colunas == COL_HORA_INICIAL_EVENTO)return "Hora Incial";
if(colunas == COL_HORA_FINAL_EVENTO)return "Hora Final";
if(colunas == COL_STATUS_EVENTO)return "Status Eventos";
return "";
}
}
package biometria.view;
import table.EventosTableModel;
import modelo.dao.EventoDAO;
import modelo.bean.Evento;
public class EventoView extends javax.swing.JFrame {
Evento evento = new Evento();
EventoDAO eventoDAO = new EventoDAO();
int n=0;
public EventoView() {
initComponents();
setLocationRelativeTo(null);//centraliza a tela JFrame
tbEvento.setModel(new EventosTableModel(new EventoDAO().listarTodos()));
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
biometriaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("biometriaPU").createEntityManager();
eventoQuery = java.beans.Beans.isDesignTime() ? null : biometriaPUEntityManager.createQuery("SELECT e FROM Evento e");
eventoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : eventoQuery.getResultList();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
tfDescricao = new javax.swing.JTextField();
tfCodigo = new javax.swing.JTextField();
btLimpar = new javax.swing.JButton();
btExcluir = new javax.swing.JButton();
btSalvar = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tbEvento = new javax.swing.JTable();
jLabel4 = new javax.swing.JLabel();
tfPesquisaDescricao = new javax.swing.JTextField();
tfHoraI = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
tfHoraF = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jCBHabilitar = new javax.swing.JCheckBox();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jCheckBoxMenuItem1.setSelected(true);
jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Produto");
setResizable(false);
jLabel1.setText("Codigo");
jLabel2.setText("Descrição");
jLabel3.setText("Status");
tfCodigo.setEditable(false);
tfCodigo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfCodigoActionPerformed(evt);
}
});
btLimpar.setText("Limpar");
btExcluir.setText("Excluir");
btExcluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btExcluirActionPerformed(evt);
}
});
btSalvar.setText("Salvar");
btSalvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSalvarActionPerformed(evt);
}
});
tbEvento.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tbEventoMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tbEvento);
if (tbEvento.getColumnModel().getColumnCount() > 0) {
tbEvento.getColumnModel().getColumn(0).setHeaderValue("Id");
tbEvento.getColumnModel().getColumn(1).setHeaderValue("Descricao");
tbEvento.getColumnModel().getColumn(2).setHeaderValue("Hora Inicio");
tbEvento.getColumnModel().getColumn(3).setHeaderValue("Hora Final");
tbEvento.getColumnModel().getColumn(4).setHeaderValue("Status");
}
jLabel4.setText("Pesquisar (Descrição)");
jLabel5.setText("Hora Inicial");
jLabel6.setText("Hora Final");
jCBHabilitar.setText("Habilita");
jCBHabilitar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCBHabilitarActionPerformed(evt);
}
});
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, eventoList, jTable1);
org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
columnBinding.setColumnName("Id");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descricao}"));
columnBinding.setColumnName("Descricao");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${horaInicio}"));
columnBinding.setColumnName("Hora Inicio");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${horaFinal}"));
columnBinding.setColumnName("Hora Final");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${status}"));
columnBinding.setColumnName("Status");
columnBinding.setColumnClass(Integer.class);
bindingGroup.addBinding(jTableBinding);
jTableBinding.bind();
jScrollPane2.setViewportView(jTable1);
if (jTable1.getColumnModel().getColumnCount() > 0) {
jTable1.getColumnModel().getColumn(4).setResizable(false);
}
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel3))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfHoraF, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
.addComponent(tfDescricao)
.addComponent(tfHoraI)
.addComponent(tfCodigo)
.addComponent(jCBHabilitar)))
.addComponent(jLabel4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(tfPesquisaDescricao, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING))))
.addGroup(layout.createSequentialGroup()
.addGap(121, 121, 121)
.addComponent(btLimpar)
.addGap(51, 51, 51)
.addComponent(btExcluir)
.addGap(46, 46, 46)
.addComponent(btSalvar))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(551, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(tfHoraI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(tfHoraF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jCBHabilitar))
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btLimpar)
.addComponent(btExcluir)
.addComponent(btSalvar))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfPesquisaDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(31, Short.MAX_VALUE))
);
bindingGroup.bind();
pack();
}// </editor-fold>
private void tfCodigoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {
if(tfCodigo.getText().equals("")){
evento.setDescricao(tfDescricao.getText());
evento.setDtini(tfHoraI.getText());
evento.setDtfin(tfHoraF.getText());
//Validacao da opcao habilitar
boolean selected = jCBHabilitar.isSelected();
if (selected == true)
{
n=1;
}
if(selected == false){
n=2;
}
evento.setStatus(n);
eventoDAO.inserir(evento);
}else{
evento.setDescricao(tfDescricao.getText());
evento.setDtini(tfHoraI.getText());
evento.setDtfin(tfHoraF.getText());
boolean selected = jCBHabilitar.isSelected();
if (selected == true)
{
n=1;
}
if(selected == false){
n=2;
}
evento.setStatus(n);
eventoDAO.alterar(evento);
}
tbEvento.setModel(new EventosTableModel(new EventoDAO().listarTodos()));
tfCodigo.setText("");
tfDescricao.setText("");
tfHoraI.setText("");
tfHoraF.setText("");
jCBHabilitar.setText("");
tfPesquisaDescricao.setText("");
}
private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jCBHabilitarActionPerformed(java.awt.event.ActionEvent evt) {
}
private void tbEventoMouseClicked(java.awt.event.MouseEvent evt) {
tfCodigo.setText(tbEvento.getValueAt(tbEvento.getSelectedRow(), EventosTableModel.COL_CODIGO_EVENTO).toString());
tfDescricao.setText(tbEvento.getValueAt(tbEvento.getSelectedRow(), EventosTableModel.COL_DESCRICAO_EVENTO).toString());
tfHoraI.setText(tbEvento.getValueAt(tbEvento.getSelectedRow(), EventosTableModel.COL_HORA_INICIAL_EVENTO).toString());
tfHoraF.setText(tbEvento.getValueAt(tbEvento.getSelectedRow(),EventosTableModel.COL_HORA_FINAL_EVENTO).toString());
jCBHabilitar.setText(tbEvento.getValueAt(tbEvento.getSelectedRow(),EventosTableModel.COL_STATUS_EVENTO).toString());
}
// Variables declaration - do not modify
private javax.persistence.EntityManager biometriaPUEntityManager;
private javax.swing.JButton btExcluir;
private javax.swing.JButton btLimpar;
private javax.swing.JButton btSalvar;
private java.util.List<biometria.view.Evento> eventoList;
private javax.persistence.Query eventoQuery;
private javax.swing.JCheckBox jCBHabilitar;
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTable tbEvento;
private javax.swing.JTextField tfCodigo;
private javax.swing.JTextField tfDescricao;
private javax.swing.JTextField tfHoraF;
private javax.swing.JTextField tfHoraI;
private javax.swing.JTextField tfPesquisaDescricao;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
}
««««««««««««««««««««««««««««««««««««««««««««««««««««
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package modelo.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import modelo.bean.Evento;
import modelo.conexao.ConnectionFactory;
import modelo.conexao.FabricaConexao;
/**
*
-
@author DTI
*/
public class EventoDAO {private Connection conn; private PreparedStatement stm; private Statement st;
private ArrayList lista =
new ArrayList();private PreparedStatement pstm; private ResultSet rs; private String sql; Connection conexao;
public EventoDAO(){
conn =
new ConnectionFactory().getConexao();
}public Evento consultarEvento() throws SQLException { //consulta
SimpleDateFormat dt = new SimpleDateFormat("HH:mm:ss"); Date hora = Calendar.getInstance().getTime(); String horformat = dt.format(hora); conexao = FabricaConexao.conexaoBanco(); sql = "SELECT * FROM evento WHERE (? > HORA_INICIO) AND (? < HORA_FINAL)"; pstm = conexao.prepareStatement(sql); pstm.setString(1, horformat); pstm.setString(2, horformat); rs = pstm.executeQuery(); Evento evento = new Evento(); while (rs.next()) { evento.setIdEvento(rs.getInt("ID")); evento.setDescricao(rs.getString("DESCRICAO")); evento.setDtini(rs.getString("HORA_INICIO")); evento.setDtfin(rs.getString("HORA_FINAL")); } FabricaConexao.fecharConexao(); return evento;
}
public Evento consultarDuplicidade (String dtini, String dtfin, int idfunc) throws SQLException{ //consultar duplicidade
SimpleDateFormat dt = new SimpleDateFormat("YYYY-MM-dd"); Date hora = Calendar.getInstance().getTime(); String horformat = dt.format(hora); String concDtini = horformat+" "+dtini; String concDtfin = horformat+" "+dtfin; conexao = FabricaConexao.conexaoBanco(); sql = "SELECT * FROM refeicao INNER JOIN evento ev on ev.ID = FK_HORARIO_REFEICAO WHERE (HORARIO_ENTRADA > ?) AND (HORARIO_ENTRADA < ?) AND FK_ID_FUNCIONARIO = ?"; pstm = conexao.prepareStatement(sql); pstm.setString(1, concDtini); pstm.setString(2, concDtfin); pstm.setInt(3, idfunc); rs = pstm.executeQuery(); Evento evento = new Evento(); while (rs.next()) { evento.setIdEvento(rs.getInt("FK_HORARIO_REFEICAO")); evento.setDescricao(rs.getString("DESCRICAO")); } FabricaConexao.fecharConexao(); return evento;
}
public void inserir(Evento evento){ //francisco String sql = “INSERT INTO evento (DESCRICAO, HORA_INICIO, HORA_FINAL, STATUS) VALUES(?,?,?,?)”; try{ stm = conn.prepareStatement(sql); stm.setString(1, evento.getDescricao()); stm.setString(2, evento.getDtini()); stm.setString(3, evento.getDtfin()); stm.setInt(4, evento.getStatus());
stm.execute(); stm.close(); } catch(SQLException erro){ throw new RuntimeException("Erro 2: Erro na inserção "+erro); }
}
public ArrayList listarTodos(){ String sql = “SELECT * FROM evento”; try { st = conn.createStatement(); rs = st.executeQuery(sql); while (rs.next()){ Evento evento = new Evento(); evento.setIdEvento(rs.getInt(“ID”)); evento.setDescricao(rs.getString(“DESCRICAO”)); evento.setDtini(rs.getString(“HORA_INICIO”)); evento.setDtfin(rs.getString(“HORA_FINAL”)); evento.setStatus(rs.getInt(“STATUS”)); lista.add(evento);
} } catch (SQLException erro){ throw new RuntimeException("Erro 5: Erro na lisa de registros:"+erro); } return lista;
}
public ArrayList listarTodosDescricao(String valor){ String sql = “SELECT * FROM evento WHERE DESCRICAO LIKE '%”+valor+"%’ "; try { st = conn.createStatement(); rs = st.executeQuery(sql); while (rs.next()){ Evento evento = new Evento();
evento.setIdEvento(rs.getInt("ID")); evento.setDescricao(rs.getString("DESCRICAO")); evento.setDtini(rs.getString("HORA_INICIO")); evento.setDtfin(rs.getString("HORA_FINAL")); evento.setStatus(rs.getInt("STATUS")); lista.add(evento); } } catch (Exception erro){ throw new RuntimeException("Erro 6: Erro na lisa de todos registros:"+erro); } return lista;
}
public void alterar(Evento evento){ String sql = "UPDATE evento SET DESCRICAO = ?, HORA_INICIO = ?, HORA_FINAL = ? WHERE ID = ? "; try{ stm = conn.prepareStatement(sql);
stm.setString(1, evento.getDescricao()); stm.setString(2, evento.getDtini()); stm.setString(3, evento.getDtfin()); stm.setInt(4, evento.getStatus()); stm.execute(); stm.close(); } catch(Exception erro){ throw new RuntimeException("Erro : 3 Erro na alteracão"+erro); }
}
public void excluir(int valor){ String sql = "DELETE FROM produto where codigo_produto = "+valor; try{ st = conn.createStatement(); st.execute(sql); st.close(); } catch(Exception erro){ throw new RuntimeException(“Erro 4: Erro na alteração do registro:”+erro);
}}
}
=================================================================
Vou tentar fazer um crud mais simples nao estou conseguindo acompanhar vcs
return evento.getStatus() == 0 ? “Habilitado” : “Desabilitado”;
…ou String[] status = { “Habilitado”, “Desabilitado” };
system.out.println("Status para 0 = " + status[0]); // imprime “Status para 0 = Habilitado”
system.out.println("Status para 1 = " + status[1]); // imprime “Status para 1 = Desabilitado”
Acho que você poderia aproveitar que está usando um JCheckBox para usar o seu método isSelected() e assim ficaria:
<strong>String statusEvento;</strong>
<strong>JCheckBox cboxStatus = new JCheckBox(“Habilita”);</strong>
<strong>…</strong>
<strong>if ( cboStatus.isSelected() )</strong>
<strong> statusEvento = “Habilitado”;</strong>
<strong>else</strong>
<strong> statusEvento = “Desabilitado”;</strong>
Boa tarde staroski e demais colegas, fiz assim como esta no final.
Resolve mas tenho outro problema, meu muito obrigado a todos.
quando clico ele nao traz o checkbox marcado.
public Object getValueAt(int linhas, int colunas) {
Evento evento = lista.get(linhas);
if(colunas == COL_CODIGO_EVENTO) return evento.getIdEvento();
if(colunas == COL_DESCRICAO_EVENTO) return evento.getDescricao();
if(colunas == COL_HORA_INICIAL_EVENTO) return evento.getDtini();
if(colunas == COL_HORA_FINAL_EVENTO) return evento.getDtfin();
// if(colunas == COL_STATUS_EVENTO) return evento.getStatus();
if (evento.getStatus() == 1){
String getStatus = "Ativado";
return getStatus;
}
if (evento.getStatus() == 2){
String getStatus = "Desativado";
return getStatus;
}
else{
String getStatus = "Verificar";
return getStatus;
}
Ok, tentei assim mas não consegui.
de qualquer forma obrigado.
muito obrigado tentei!
Que tal um pouco mais legível?
public Object getValueAt(int linha, int coluna) {
Evento evento = lista.get(linha);
switch (coluna) {
case COL_CODIGO_EVENTO:
return evento.getIdEvento();
case COL_DESCRICAO_EVENTO:
return evento.getDescricao();
case COL_HORA_INICIAL_EVENTO:
return evento.getDtini();
case COL_HORA_FINAL_EVENTO:
return evento.getDtfin();
case COL_STATUS_EVENTO:
switch (evento.getStatus()) {
case 1:
return "Ativado";
case 2:
return "Desativado";
default:
return "Verificar";
}
}
}
Perfeito muito obrigado,agora estou na luta para o checkbox dele ficar marcado sempre que a linha for selecionada e desde que esteja ativo e vice -versa.

meuCheckBox.setSelected( eventoSelecionado.getStatus() == 1 );