Results 1 to 3 of 3
  1. #1
    Gatts79 is offline Member
    Join Date
    Aug 2008
    Rep Power

    Default Problems getting JTable to display information

    Hello All -

    So I'm making a file browser/chooser. I am useing a JTable to display a list of files that i query from a sql database. I am using a JTable because i want to display the information as name, and description in the window. I am using a JComboBox as a filter device of what to display in the window.

    So the problem is when it opens up nothing is displayed but the default table information (title1, title2, title3, title4).

    These are the steps the code goes in when executed (note that everything is done in netbeans):

    String[] columnNames = {"Name", "Description"};
    Object[][] data = null;

    {... SQL Queries here...}

    ArrayList<String[]> m_data = loadSQLData(query);
    data = new Object[m_data.size()][columnNames.length];
    for (int i = 0; i < data.length; i++) {
    for (int j = 0; j < data[i].length; j++) {
    data[i][j] = m_data.get(i)[j];

    DefaultTableModel tabModel = new DefaultTableModel(data, columnNames);
    jTable1 = new JTable(tabModel);

    So basically the code queries the database and returns an ArrayList<String[]> with each string array representing a row. In my console window I see the code query the server, connect and grab the information i queried (I have the console output retrieval info). I step throught he code and the jTabel1 is valid and has all the information I queried from the server. I can even retrieve the information in each cell using the jTable1.getValueAt(row, col);. So i know the data is there.

    The problem is that i don't see any of that information in the cells. It just displays the default info set by netbeans. I've even tried setting a TableCellRenderer and nothing changes. There is a scrollpane which the table resides in and its already been added, not sure if it was necessary, but
    figured it would be nice to have in place just in case.

    Thanks In Advance,


  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    I think you need a better understanding of objects and references. You have a table added to your GUI, then you reassign the variable jTable1 to a new JTable. That does not replace the table in the GUI.

    You need to setModel on the existing table.
    Java Code:
    // jTable1 = new JTable(tabModel);

  3. #3
    Gatts79 is offline Member
    Join Date
    Aug 2008
    Rep Power


    Thanks for the reply Daryl-

    After posting the message yesturday I figured out just that. I don't know why I didn't see the answer earlier. What you say makes alot of sence. Thanks again.

Similar Threads

  1. Display XML in JTable
    By boy22 in forum XML
    Replies: 2
    Last Post: 12-07-2008, 06:03 PM
  2. Replies: 0
    Last Post: 06-28-2008, 09:26 PM
  3. Adding information to a JTable in a JTabbedPane
    By bigpappatrader in forum AWT / Swing
    Replies: 0
    Last Post: 12-05-2007, 07:09 AM
  4. Swing program to display JVM information
    By satya007 in forum AWT / Swing
    Replies: 3
    Last Post: 11-13-2007, 09:59 AM
  5. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts