-1
這裏是我的代碼:現有員額不斷重新加入到JTable中與較新的帖子
public void submitReply(ActionEvent e) {
String replyBy = userName;
String reply = jTextArea_reply.getText();
if (reply.equals("")) {
JOptionPane.showMessageDialog(null, "Comment cannot leave blank");
} else {
eForumTopics comment = new eForumTopics(replyBy, reply);
if (comment.createComment() == true) {
JOptionPane
.showMessageDialog(null,
"Reply submitreted successfully. You will be redirect to main page.");
SetUpJTableComment();
public void SetUpJTableComment() {
// Get jTable model
DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
.getModel();
// Store column data into Array (3 columns)
String[] data = new String[3];
// Set Up Database Source
db.setUp("IT Innovation Project");
String sql = "Select reply_content,reply_by from forumReplies WHERE reply_topic = "
+ topicId + "";
ResultSet resultSet = null;
// Call readRequest to get the result
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
data[0] = resultSet.getString("reply_content");
data[1] = resultSet.getString("reply_by");
// Add data to table model
tableModel1.addRow(data);
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
// add tablemodel to jtable
}
的問題是,每當用戶發佈一個新的回覆,則現有職位將被重新加在一起。我試圖做的只是將評論框中的新回覆添加到jTable中,而不是繼續用新回覆重新添加現有帖子。我該用什麼?一個for循環?提前致謝。
同樣次優(您被告知無需再次設置模型)代碼片段與您的最後一個問題 - 如何開始挖掘真正的錯誤? – kleopatra
加:學習java的命名約定,並堅持他們 - **現在** – kleopatra
我已經編輯過,所以我應該怎麼做,以防止現有的職位繼續重新添加? –