5 Replies - 1827 Views - Last Post: 17 April 2012 - 07:33 PM Rate Topic: -----

#1 Twister1002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-April 12

Not able to show all data in JTable

Posted 16 April 2012 - 07:39 PM

Hey everyone! I've been experimenting with the JTable and trying to get it to output data I want to put in it. However, without trying to do anything messy just yet.

Objective: Populate the JTable with data from the ResultSet

Issue: When using a ResultSet to fill the JTable, I am outputting information. More than just 1 row or column and I need the Jtable to repopulate with different data when a refresh button is executed. (Just the same code done twice really).


        DefaultTableModel customerModel = (DefaultTableModel)allCustomers.getModel();
        customerModel.fireTableDataChanged();
        customerModel.fireTableStructureChanged();
        
        ResultSet customerData = select.getResultSet("customers");
        int columnCount = select.getColumnCount(customerData);
        
        System.out.println("Column Count: "+columnCount);
// Returns 11. Is not a value I defined.
        System.out.println("Empty ResultSet:"+select.emptyResultSet(customerData));
// Returns false, which means the ResultSet is NOT null
        
        Object[] data = new Object[columnCount];
        String[] columnNames = new String[columnCount];

        try{
            for(int i = 1; i < columnCount; i++){
                columnNames[i] = select.getColumnName(i);
            }

            if(customerData.next()){
                while(customerData.next()){
                    for(int i = 1; i < columnCount; i++){
                        data[i] = customerData.getObject(i);
                    }
                    customerModel.addRow(data);
                }
            }
            else{
                data[0] = "No Results";
                customerModel.addRow(data);
            }
            
            customerModel.setColumnIdentifiers(columnNames);
            allCustomers.setModel(customerModel);
            
        }
        catch(Exception e){
            System.err.println("Error showing results. Exception thrown: "+e);
            e.printStackTrace();
        }
    }                                                



I do know some things though:
The columnCount is 11, so the ResultSet is truly working.
select.emptyResultSet() shows False. Which means the ResultSet is NOT null.
When the refresh button is clicked, it just adds more white space with no other changes.

Now, the output for the JTable that it shows is:
(Columns) A
(Rows) (shows nothing)

So I'm stumped and I've been looking on Google for a really long time.

Any help or suggestions is greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Not able to show all data in JTable

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Not able to show all data in JTable

Posted 16 April 2012 - 07:47 PM

You can go directly from San Francisco to Seatle or pass by New York
Why do you want to pass by New York ?

Write your own TableModel
Was This Post Helpful? 0
  • +
  • -

#3 Twister1002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-April 12

Re: Not able to show all data in JTable

Posted 16 April 2012 - 07:50 PM

View Postpbl, on 16 April 2012 - 09:47 PM, said:

You can go directly from San Francisco to Seatle or pass by New York
Why do you want to pass by New York ?

Write your own TableModel



I eventually will. But for now, I'm trying to learn how to do it with the sources I have available to me right now.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Not able to show all data in JTable

Posted 16 April 2012 - 07:56 PM

Don't want to discourage you but you are not on the good path to achieve that goal
anyhow, you can take all "intermediate" steps to try to reach that goal. Good luck
Was This Post Helpful? 0
  • +
  • -

#5 Twister1002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-April 12

Re: Not able to show all data in JTable

Posted 16 April 2012 - 08:02 PM

From my past experience, you have to be able to start from somewhere, learn from it, then improve what you have done. You can't expect to learn something at an expert level if you are a beginner level just trying to understand a concept higher than you can understand.

You are not discouraging me, in fact its encouraging. I do understand that this may not be the best method out there to use, however, I dont know of any other methods to actually build a table from scratch.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Not able to show all data in JTable

Posted 17 April 2012 - 07:33 PM

Great attitude :^: other newbies would have been pissed off :)
That can help you, I hope

http://www.dreaminco...h-a-tablemodel/

wouldn't have writen it for nothing. May be you'll mention me in your autobiography :)

This post has been edited by pbl: 17 April 2012 - 07:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1