Results 1 to 3 of 3
- 11-07-2008, 01:18 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
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
- 11-07-2008, 08:35 AM #2
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.dbJava Code:// jTable1 = new JTable(tabModel); jTable1.setModel(tabModel);
- 11-08-2008, 02:35 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Display XML in JTable
By boy22 in forum XMLReplies: 2Last Post: 12-07-2008, 06:03 PM -
How to display information about the display device in SWT
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:26 PM -
Adding information to a JTable in a JTabbedPane
By bigpappatrader in forum AWT / SwingReplies: 0Last Post: 12-05-2007, 07:09 AM -
Swing program to display JVM information
By satya007 in forum AWT / SwingReplies: 3Last Post: 11-13-2007, 09:59 AM -
display rows in jtable
By osval in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks