Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-07-2008, 03:18 AM
Member
 
Join Date: Aug 2008
Posts: 11
Gatts79 is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 11-07-2008, 10:35 AM
Senior Member
 
Join Date: Sep 2008
Posts: 317
Darryl.Burke is on a distinguished road
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, 04:35 AM
Member
 
Join Date: Aug 2008
Posts: 11
Gatts79 is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 08:03 PM
How to display information about the display device in SWT Java Tip SWT 0 06-28-2008 11:26 PM
Adding information to a JTable in a JTabbedPane bigpappatrader AWT / Swing 0 12-05-2007 09:09 AM
Swing program to display JVM information satya007 AWT / Swing 3 11-13-2007 11:59 AM
display rows in jtable osval AWT / Swing 1 08-06-2007 10:54 PM


All times are GMT +3. The time now is 11:38 AM.


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