Hey guys, I have this code wherein I have 4 buttons to determine what set of values to display on my jtable. I've successfully displayed my data.
After running the program, clicking a button, data is displayed in the jtable. Problem is, when I minimize/maximize the window, the data disappears. I can't click the rows. I want the rows to be clickable and not disappear. I want to know how this work. Please help me guys. This is my code.
private void display(int yr){
try {
DefaultTableModel model = (DefaultTableModel) schedTable.getModel();
int ctr = 0;
//removes the previously selected set of data
while(ctr < model.getRowCount()){
model.removeRow(ctr);
}
ctr = 0
PreparedStatement stmt = con.prepareStatement("select * from APP.SCHEDULE where yr=" + yr);
ResultSet sched = stmt.executeQuery();
while(sched.next()){
PreparedStatement stmt2 = con.prepareStatement("select * from APP.SUBJECT where subjectNumber='" + sched.getString("subjectNum") + "'");
ResultSet subj = stmt2.executeQuery();
subj.next();
model.addRow(new Object[] {
sched.getInt("numOfStud"),
subj.getString("name"),
subj.getInt("unit"),
sched.getString("day") + " " + sched.getString("startTime") + " - " + sched.getString("endTime"),
sched.getString("room"),
sched.getInt("yr")
});
model.fireTableRowsInserted(ctr, ctr);
++ctr;
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}