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 9022621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:33:30+00:00 2026-06-16T05:33:30+00:00

These are my codes for my jTable in java swing. private JTable getJTable() {

  • 0

These are my codes for my jTable in java swing.

private JTable getJTable() {
    if (jTable == null) {
        Vector columnNames = new Vector(); //Vector class allows dynamic array of objects
        Vector data = new Vector();
        JPanel panel = new JPanel();   
        panel.setSize(new Dimension(198, 106));

        try {
            DBController db = new DBController();
            db.setUp("IT Innovation Project");
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
            String dsn = "IT Innovation Project";
            String s = "jdbc:odbc:" + dsn;
            Connection con = DriverManager.getConnection(s, "", "");
            String sql = "Select * from forumTopics";
            java.sql.Statement statement = con.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columns = metaData.getColumnCount();

            for (int i = 1; i <= columns; i++) {
                columnNames.addElement(metaData.getColumnName(i));
            }

            while (resultSet.next()) {
                Vector row = new Vector(columns);
                for (int i = 1; i <= columns; i++) {
                    row.addElement(resultSet.getObject(i));
                }
                data.addElement(row);
            }

            resultSet.close();
            ((Connection) statement).close();
        } catch (Exception e) {
            System.out.println(e);
        }

        jTable = new JTable(data, columnNames);
        TableColumn column;

        for (int i = 0; i < jTable.getColumnCount(); i++) {
            column = jTable.getColumnModel().getColumn(i);
            column.setMaxWidth(250);
        }

        String header[] = {"description", "title", "category", "posted by"};  

        for(int i=0;i<jTable.getColumnCount();i++) { 
            TableColumn column1 = jTable.getTableHeader().getColumnModel().getColumn(i);    
            column1.setHeaderValue(header[i]);  
        } 

        jTable.setBounds(new Rectangle(82, 218, 736, 292));
        jTable.setEnabled(false);
        jTable.setRowHeight(50);
        jTable.getRowHeight();         
    }
    return jTable;
}

I set an array for the header of my table. However, the program only shows the data inside my database without any header. Can somebody please enlighten me? 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-16T05:33:32+00:00Added an answer on June 16, 2026 at 5:33 am

    Put your JTable in JScrollPane like

    add(new JScrollPane( getJTable() ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I add tooltips to JTable's rows (Java Swing)? These tooltips should contain
What are the differences between these two codes in JavaScript? var obj = new
JAVA NETBEANS // resultsTable, myModel JTable resultsTable; DefaultTableModel myModel; //javax.swing.table.DefaultTableModel myModel = (DefaultTableModel) resultsTable.getModel();
I have these codes for my two tabs. I would like to change the
I created two dropdpwn calendar in my form with these codes: <script type=text/javascript src=http://code.jquery.com/jquery-latest.js></script>
I tried to get avatar at single (post) page by these codes <?php echo
My mainTable has column primaryCode. These codes are incorrect and need to be updated
these below codes give whole data of my Rehber datas. But if i want
What is the difference between these two codes : public uint? a; public uint
I have these code in my views.py: array = [] p = Person.objects.filter(client=1,status='Complete').values('name', 'age',

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.