Ola All
public static void showDatabaseTable() {
gridRows.clear();
gridColumns.clear();
jPanel1.removeAll();
jPanel1.updateUI();
jPanel1.validate();
jTable1.updateUI();
try {
try {
Properties Banco = new Properties();
try {
Banco.load(new FileInputStream("/Arkade/Imobille/config.dat"));
} catch (IOException e)
{
JOptionPane.showMessageDialog(null,"Erro de Leitura no Arquivo de Configuração");
}
url = "jdbc:"+Banco.getProperty("TypeNBANCO")+"://"+Banco.getProperty("ServerNAME")+":"+Banco.getProperty("PortNUMBER")+"/"+Banco.getProperty("MyDATABASE")+"?user="+Banco.getProperty("MyUSERNAME")+"&password="+Banco.getProperty("MyPASSWORD");
Class.forName(Banco.getProperty("DriverNAME"));
}
catch(ClassNotFoundException cnfx) {
cnfx.printStackTrace();
JOptionPane.showMessageDialog(null,"O Sistema não obteve acesso ao Banco de Dados");
}
catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"O Sistema não obteve acesso ao Banco de Dados");
}
Connection conexao = DriverManager.getConnection(url);
Statement st = conexao.createStatement();
ResultSet rec = st.executeQuery("SELECT Codigo, Nome, Departamento FROM corretores ORDER BY Nome ");
displayDatabaseRecords(rec);
jTable1.updateUI();
st.close();
}
catch (SQLException sqlx) {
sqlx.printStackTrace();
}
}
private static void displayDatabaseRecords(ResultSet rS) throws SQLException {
boolean moreRecords = rS.next();
if (!moreRecords) {
}
try {
ResultSetMetaData rs = rS.getMetaData();
for (int i = 1; i <= rs.getColumnCount(); ++i)
gridColumns.addElement(rs.getColumnName(i));
do {
gridRows.addElement(getNextRow(rS,rs));
} while (rS.next());
jTable1 = new JTable(gridRows, gridColumns) {
public Component prepareRenderer(TableCellRenderer renderer,
int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
c.setBackground(Color.lightGray);
} else {
c.setBackground(getBackground());
}
return c;
}
};
int vColIndex = 0;
jTable1.getColumnModel().getColumn(vColIndex).setHeaderValue("CODIGO");
jTable1.getColumnModel().getColumn(vColIndex).setMaxWidth(80);
vColIndex = 1;
jTable1.getColumnModel().getColumn(vColIndex).setHeaderValue("NOME");
vColIndex = 2;
jTable1.getColumnModel().getColumn(vColIndex).setHeaderValue("DEPARTAMENTO");
jTable1.setOpaque(true);
jTable1.setBackground(new java.awt.Color(255, 255, 255));
JScrollPane scroller = new JScrollPane(jTable1);
scroller.setBackground(new java.awt.Color(255, 255, 255));
scroller.setOpaque(true);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setOpaque(true);
jTable1.setRowHeight(20);
jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable1.setRowSelectionAllowed(true);
jPanel1.add(scroller);
scroller.revalidate();
jTable1.revalidate();
}
catch(SQLException sqlx) {
sqlx.printStackTrace();
}
}
private static Vector getNextRow(ResultSet rS, ResultSetMetaData rs) throws SQLException {
Vector currentRow = new Vector();
for (int i = 1; i <= rs.getColumnCount(); ++i)
if (rs.getColumnType(i) == Types.VARCHAR) {
currentRow.addElement(rS.getString(i));
}
else if (rs.getColumnType(i) == Types.INTEGER)
{
currentRow.addElement(rS.getString(i));
}
return currentRow;
}
Andei dando uma olhada nos topicos, mas não consegui fazer, se alguem puder dar uma olhada no meu codigo e me ajudar a colocar o jCheckBox na minha jTable eu ficaria muito grato.
T+
Renato