Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:53+00:00 2026-06-17T10:33:53+00:00

I try to do for forum using java swing. Here are my codes for

  • 0

I try to do for forum using java swing. Here are my codes for table :

    public void SetUpJTable() {
    DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
    String[] data = new String[4];
    db.setUp("IT Innovation Project");
    String sql = "Select topic_title,topic_description,topic_by from forumTopics WHERE topic_id = "
            + topicId + "";
    ResultSet resultSet = null;
    resultSet = db.readRequest(sql);
    try {
        while (resultSet.next()) {
            data[0] = resultSet.getString("topic_title");
            data[1] = resultSet.getString("topic_description");
            data[2] = resultSet.getString("topic_by");
            tableModel.addRow(data);        
        }
        resultSet.close();
    } catch (Exception e) {
        System.out.println(e);
    }
}

I set up this table to retrieve the topic details which user select certain thread from main page. And I set up another table to store for the replies by users. Here is it :

    public void SetUpJTableComment() {
    DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
            .getModel();
    String[] data = new String[3];
    db.setUp("IT Innovation Project");
    String sql = "Select reply_content,reply_by from forumReplies WHERE reply_topic = "
            + topicId + "";
    ResultSet resultSet = null;
    resultSet = db.readRequest(sql);
    try {
        while (resultSet.next()) {
            data[0] = resultSet.getString("reply_content");
            data[1] = resultSet.getString("reply_by");
            tableModel1.addRow(data);
        }
        resultSet.close();
    } catch (Exception e) {
        System.out.println(e);
    }
}

And this is how I set up the table :

    private JTable getJTableComment() {
    String header[] = { "Comment", "Reply By" };
    if (jTableComment == null) {
        jTableComment = new JTable() {
            public boolean isCellEditable(int nRow, int nCol) {
                return false;
            }
        };
    }
    DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
            .getModel();
    tableModel1.setColumnIdentifiers(header);

    jTableComment.getColumnModel().getColumn(0).setMinWidth(700);
    jTableComment.getColumnModel().getColumn(0).setMaxWidth(800);

    jTableComment.getColumnModel().getColumn(1).setMinWidth(97);
    jTableComment.getColumnModel().getColumn(1).setMaxWidth(100);

    jTableComment.getTableHeader().setFont(
            new Font("Dialog", Font.PLAIN, 20));
    jTableComment.getTableHeader().setForeground(Color.white);
    jTableComment.getTableHeader().setBackground(new Color(102, 102, 102));
    jTableComment.setRowHeight(50);
    jTableComment.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jTableComment.setFont(new Font("Dialog", Font.PLAIN, 18));
    return jTableComment;
}

It works perfectly with two separating tables. I wonder if there is some way to combine both of these tables into one table? And how can I customize the table to make it look less-liked a table because my current one is just .. solid-table and my teacher asked me to improve it but I have no idea to do so. And I tried to add button into the table but I realized that I cannot add it from the try statement because that is is retrieve data from database directly. Any guides? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:33:54+00:00Added an answer on June 17, 2026 at 10:33 am

    You can use SQL join construct and have one table with more columns:

    select topic_title,topic_description,topic_by,
           reply_content,reply_by 
             from forumTopics join forumReplies 
               on (forumTopics.topic_id=forumReplies.topic_id)  WHERE topic_id = 1234
    

    then build the model from the five column result set as you are already doing.

    But surely if there is more than one reply to a forum topic, the topic part will be repeated in the table.

    To make a table not to look like a table, try JTreeTable from Swing Labs maybe, it allows to have tree-like subsections, exactly that is required. It is not part of the system library however, you will need to download it. Some source code on how to just JTreeTable can be found here.

    On how JTreeTable looks is Swing Labs, you can see in they web-startable demo. It also shows the code sample automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Swing GUI using netbeans, and when I try to manually do
I'm using java.text.SimpleDateFormat to parse strings of the form yyyyMMdd . If I try
Using JAVA, I'm trying to force the browser to download files. Here is the
I have an Idea to develop a java Swing application using the MVC pattern.
I'm coding in Swing in Java. I'm using the Netbeans layout manager. I'm having
I'm trying to invoke a method with variable arguments using java reflection. Here's the
I'm try to validate form using jquery validation plugin my from code: source code
http://www.dorsetdesigns.co.uk/contact.html try the form it wont send a email to me. i am using
i try to validate the form before submitting the request. i am using jquery
No luck asking this question on the AWS forum , so will try my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.