jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Populate a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Populate a JTable" Watch "Populate a JTable" New topic

Populate a JTable

Russ Wright

Joined: Dec 20, 2003
Posts: 7
Okay I know there are other messages about this but I could not find one to solve my problem.
I have a Jform. On the form I have placed a JScrollPane on top of the JScrollPane I have placed a swing.JTable.
I'm using netbeans 3.5.1 and using the gui creator which created a function called initcomponents() In there this is how netbeans set up the controls:
JTblDonations.setModel(new javax.swing.table.DefaultTableModel(
new Object [][]
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
new String []
"Title 1", "Title 2", "Title 3", "Title 4"
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 270, 390, 100));

Now later in my code I have a function that gets some data from a MySQL table and puts it in a class level recordset called m_RSDonations. Then I want to display this recordset in the JTable created in the initComponents() function described above. My code is below. How DO I get the records to display??
Thanks in advance
My Code:
private void displayDonations()
* Function Name: displayDonations
* //based somewhat on code from Deitel and Dietel
* Purpose: to display the donations on the interface
* Inputs ResultSet rS
* Outputs: grid rs
* change log
* date initials description
* 12/12/2003 rww iniial creatiion
gridColumns = new Vector();
gridRows = new Vector();
{ //move to first record
//get the column headers
ResultSetMetaData rs = m_RSDonations.getMetaData();
for (int i = 1; i <= rs.getColumnCount(); ++i)
//if records exist build a grid
while (m_RSDonations.next());
//create table
//******WHAT DO I DO HERE???
catch(SQLException sqlx)
private Vector getNextRow(ResultSet rS, ResultSetMetaData rs) throws SQLException
Vector currentRow = new Vector();
for (int i = 1; i <= rs.getColumnCount(); ++i)
if (rs.getColumnType(i) == Types.VARCHAR)
//Ab.connectField.setText("Type was: " + rs.getColumnTypeName(i));
return currentRow;
} //end getnextrow
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link: http://aspose.com/file-tools
subject: Populate a JTable
It's not a secret anymore!