• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Populate a JTable

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
[ December 21, 2003: Message edited by: Dirk Schreckmann ]
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic