I have 2 JTables; table1 and table2. table1 contains the data from the database whilst table2 holds no data, atleast not yet.
What I wanted to do is that when I double click a row in table1, that specific row will be displayed in table2 so on and so forth.
Here's my code so far:
//Table1: (This is just some few codes, I didnt bother putting all of the codes
// since this is self explanatory)
public void tabledbinfo() {
con = mysqlConnection.dbConnector();
String sql = "select main_id,cat_name,product_name,amount_value from main " +
"inner join category " +
"on main.catId = category.catId "+
"inner join product "+
"on main.proId = product.proId "+
"inner join price " +
"on main.priceId = price.priceId ";
try {
prs = con.prepareStatement(sql);
rs = prs.executeQuery();
Object[] trow;
while(rs.next()) {
trow = new Object[]{rs.getString(1),
rs.getString(2),
rs.getString(3),
rs.getString(4)};
dtm.addRow(trow);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void tablemodel(){
dtm = new DefaultTableModel(dbinfo,columns){
public boolean isCellEditable(int row,int column){
return false;
}
public Class getColumnClass(int column){
Class returnValue;
if ((column >= 0) && (column < getColumnCount())){
returnValue = getValueAt(0,column).getClass();
}else{
returnValue = Object.class;
}
return returnValue;
}
};
No comments:
Post a Comment