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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:46:48+00:00 2026-06-01T22:46:48+00:00

I am new to swing and I have just started working on it as

  • 0

I am new to swing and I have just started working on it as apart of my class work. Do forgive me if the question is irrelevant.
I am trying to put a table with some data from data base on a frame. What i have done is that I have created a JFrame Form. This form is blank. Now i am trying to populate a table, put it on a scroll Pane and finally add this scroll pane to my frame.

I am able to display the table by creating a new frame from the current frame. But what i want is add the table to the current Jframe form.

Here is what I have done:

package com.air.form;
import com.air.db.Transaction;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.JTable;



public class FlightDetails extends javax.swing.JFrame {


    /** Creates new form FlightDetails */

    public FlightDetails() {
        initComponents();
    }
     FlightDetails(String src,String dest) {
        initComponents();
        initialise(src,dest);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 603, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }


    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FlightDetails().setVisible(true);
            }
        });
    }
    private void initialise(String src, String dest)
    {
        Transaction tn=new Transaction();
        try
        {


            ResultSet result = tn.ReturnFlightDetails(src,dest);
            ResultSetMetaData md = result.getMetaData();
            int columnCount = md.getColumnCount();

            Vector columns = new Vector(columnCount);

            //store column names
            for(int i=1; i<=columnCount; i++)
            columns.add(md.getColumnName(i));

            Vector data = new Vector();
            Vector row;

            //store row data
            while(result.next())

            {
                row = new Vector(columnCount);
                for(int i=1; i<=columnCount; i++)
                {
                    row.add(result.getString(i));
                }
                data.add(row);
            }
            JTable table = new JTable(data, columns);
            JScrollPane scrollPane = new JScrollPane(table);
        }
        catch(Exception e)
        {

        }

    }


}
  • 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-01T22:46:50+00:00Added an answer on June 1, 2026 at 10:46 pm

    JFrame is a Container which has the add method to add Components to it. Depending on the layout manager, you need to pass some constraints as well. I do not see any of such calls in your code. You just create a table, but does not add it to any container.

    As this is homework, I just going to include some extra links:

    • Swing tutorial on panels
    • Swing tutorial on layout managers
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new to netbeans ide , i have a swing desktop application and
I'm new in netbeans and java swing, but also confused. I put some JLabel's
I have a java application for an ATC. I just got started with the
I'm trying to build a new java swing component, I realise that I might
I've just started Java and we have been asked to produce pong (or a
I have just started studying JOGL and there is one problem. Below is simple
I just started to learn swing by myself, I'm little bit confused why my
I am trying to write an OSGi based desktop application. I have a Swing
I just started doing Java Swing applications using MVC pattern and so far i
I'm relatively new to java (specifically swing) and have recently been making some fairly

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.