I tried to create a forum in java swing. Currently I have different categories. The topics are differentiate by topicId. I try to do like when I click on certain row within certain categories, then the app will redirect to certain thread content filtering by topicId.
For example, I have a thread. The thread is in Disscussion category and topidId is 5. When I clicked on Discussion section on forum main page, it will redirect me to a table which filtered by category in database. Then when I click on the thread which is in row 3 of the jTable, it will display me the data of topicId 5 in database.
I know there is some way to do this by using getSelectedRow method in jTable. So here are my codes :
jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
int viewRow = jTable.getSelectedRow();
if (viewRow >= 0) {
topicId = jTable.convertRowIndexToModel(viewRow);
System.out.println(topicId);
}
}
}
});
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
eForumTopics topics = new eForumTopics(topicId);
topics.retrieveThread();
getJFrame().dispose();
eForumThreadContent myWindow = new eForumThreadContent(topicId);
myWindow.getJFrame().setVisible(true);
}
});
Here is my retrieveThread method :
public boolean retrieveThread(){
boolean success = false;
ResultSet rs = null;
DBController db = new DBController();
db.setUp("IT Innovation Project");
String dbQuery = "SELECT topic_title,topic_description,topic_by FROM forumTopics WHERE topic_id = " + topicId
+ "";
rs = db.readRequest(dbQuery);
db.terminate();
return success;
}
}
I got an Id column at column 0 of jTable. So whenever user clicked on certain row, the Id of that row will store into topicId and execute the following. However, this app keep returning me row 0 even when I clicked on different rows. So is there any other ways to display topic views of a forum in java swing? I mean if not using the getSelectedRow method to get the topicId. Thanks in advance.