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

  • SEARCH
  • Home
  • 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 6696775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:22:52+00:00 2026-05-26T06:22:52+00:00

I am creating a table at run time after fetching the result from the

  • 0

I am creating a table at run time after fetching the result from the database. The flow of my application is like this.

  1. Initializing a empty JScrollPane(); JScrollPane tableScroll = new JScrollPane();
  2. Fetching result from the database;
  3. Updating result to JTable and adding JTable to JScrollPane using following method:

Code:

private void setResultTable(Vector documents, Vector header) {
   TableModel model = new DefaultTableModel(documents, header);
   documentTable.setModel(model);
   tableScroll.add(documentTable);
   tableScroll.repaint();
}

my problem is that after calling setResultTable the result are not appearing in the table. Please help me with that. 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-05-26T06:22:53+00:00Added an answer on May 26, 2026 at 6:22 am

    You appear to be adding the JTable directly to the JScrollPane. If so this isn’t correct and you’ll want to change this so that you’re actually adding the table to the scroll pane’s viewport:

    tableScroll.getViewport().add(documentTable);
    

    There is no need to repaint the JScrollPane after doing this.

    For example:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    
    public class AddTableToScroll {
       public static void main(String[] args) {
          final JScrollPane sPane = new JScrollPane();
    
          // Sorry Jeanette!!
          sPane.setPreferredSize(new Dimension(200, 150));
    
          JButton button = new JButton(new AbstractAction("Press Me!") {
    
             public void actionPerformed(ActionEvent arg0) {
                DefaultTableModel model = new DefaultTableModel(new Integer[][] {
                      { 1, 2 }, { 3, 4 } }, new String[] { "A", "B" });
                JTable table = new JTable(model);
    
                sPane.getViewport().add(table);
    
             }
          });
    
          JPanel panel = new JPanel();
          panel.add(sPane);
          panel.add(button);
    
          JOptionPane.showMessageDialog(null, panel);
    
       }
    }
    

    If this doesn’t help, you’ll want to also tell us exactly what happens, what you see, and if possible supply us with a small compilable runnable program that demonstrates your problem, an SSCCE

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

Sidebar

Related Questions

People suggest creating database table dynamically (or, in run-time) should be avoided, with the
I'm creating a table that looks something like this. CREATE TABLE packages ( productCode
After creating a table (by migration), I want to insert some entries directly. How
I am creating a table for an application that handles scheduling and deals with
Let's say you're creating a database to store messages for a chat room application.
Just wondering if it's possible to databind a RDLC's table at run time. I've
I'm creating a table in VBA within a loop and when I run the
Rather than creating row after row of test data one at a time, is
I have a few questions about creating a database from a model. Is it
In runtime I'm creating a DataTable and using nested for-loops to populate the table.

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.