Solved

unable to display data in JTable at runtime

Posted on 2004-10-25
321 Views
Last Modified: 2008-03-03
I did create a JTable on GUI and tried to display data on it.I am getting the data on table but it is not displaying at run time.

The sample code is :

this.TblReport=FillTable(new javax.swing.JTable(),rs);

//this.TblReport is the JTable object created at designe time by using NetBeans IDE.
// rs is a ResultSet with data.

I have all the data in TblReport object, but it is not displaying. what will be the problem?. anyone can help me?.



 public javax.swing.JTable FillTable (javax.swing.JTable table, ResultSet rs) {

....
....
return new javax.swing.JTable(rows, columnNames);

//rows and columnNames are data vectors for data and columns of the table.
}
0
Question by:tstName
    5 Comments
     
    LVL 37

    Expert Comment

    by:zzynx
    Better not replacing the JTable but the data of the table's model
    0
     
    LVL 92

    Expert Comment

    by:objects

    try:

    this.TblReport=FillTable(rs);



     public javax.swing.JTable FillTable (ResultSet rs) {

    ....
    ....
    return new javax.swing.JTable(rows, columnNames);

    //rows and columnNames are data vectors for data and columns of the table.
    }
    0
     
    LVL 37

    Accepted Solution

    by:
    Try this:


    this.TblReport.setModel( getModel(rs) );

    with

    public javax.swing.table.DefaultTableModel getModel(ResultSet rs) {

         ...
         return new javax.swing.table.DefaultTableModel(rows, columnNames);
    }
    0
     

    Author Comment

    by:tstName
    thank you zzynx, your method is working fine.
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    Thanks for accepting

    >> your method is working fine
    Just wondering why you gave it a B then...
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now