Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-07-2008, 01:18 AM
Member
 
Join Date: Aug 2008
Posts: 14
Rep Power: 0
Gatts79 is on a distinguished road
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);
jTable1.setVisible(true);

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,

Gatts
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-07-2008, 08:35 AM
Senior Member
 
Join Date: Sep 2008
Posts: 607
Rep Power: 1
Darryl.Burke is on a distinguished road
Default
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.
Code:
// jTable1 = new JTable(tabModel);
jTable1.setModel(tabModel);
db
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-08-2008, 02:35 AM
Member
 
Join Date: Aug 2008
Posts: 14
Rep Power: 0
Gatts79 is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display XML in JTable boy22 XML 2 12-07-2008 06:03 PM
How to display information about the display device in SWT Java Tip SWT 0 06-28-2008 09:26 PM
Adding information to a JTable in a JTabbedPane bigpappatrader AWT / Swing 0 12-05-2007 07:09 AM
Swing program to display JVM information satya007 AWT / Swing 3 11-13-2007 09:59 AM
display rows in jtable osval AWT / Swing 1 08-06-2007 08:54 PM


All times are GMT +2. The time now is 11:09 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org