File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what am i doing wrong

 
john mattucci
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IM TRYING TO ADD A ROW TO A JTABLE, AND FOR SOME REASON ITS NOT WORKING, WHAT AM I DOING WRONG I HAVE LOOKED THROUGH 100+
PAGES AND I HAVE FOUND NOTHING
private JTable getScrollPaneTable()
{
if (ivjScrollPaneTable == null)
{
try
{
dm = new DefaultTableModel(o,1);
ivjScrollPaneTable = new JTable(dm)
{
public void tableChanged(TableModelEvent e)
{
super.tableChanged(e);
int row = e.getFirstRow();
int column = e.getColumn();

if(column == 1 && isWord((String)getValueAt(row, column)))
{
Object o[] = null;

dm.setNumRows(2);

dm.addRow(o);
}
repaint();
}

private boolean isWord(String param)
{
char c [] = param.toCharArray();
int size = c.length;
Character test = new Character(c[0]);
for(int i = 0; i < size; i++)
{
if(test.isLetter(c[i]))
return true;

}
return false;
}
};
getJScrollPane1().setColumnHeaderView(ivjScrollPaneTable.getTableHeader());
getJScrollPane1().getViewport().setBackingStoreEnabled(true);
ivjScrollPaneTable.setModel(dm);
initColumnSizes(ivjScrollPaneTable, dm);
//ivjScrollPaneTable.sizeColumnsToFit(3);
ivjScrollPaneTable.setCellSelectionEnabled(true);
ivjScrollPaneTable.setColumnSelectionAllowed(true);
ivjScrollPaneTable.setBounds(0, 0, 200, 200);
ivjScrollPaneTable.setRowHeight(22);

return ivjScrollPaneTable;
}
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I'm not sure for what's that if-clause. anyway, you're adding the row inside this if-clause. more exactly you're adding:
Object[] o = null;
dm.addRow(o);
thus you're adding the value null. setting the rows is not necessary, i never did that. I extend the DefaultTableModel. the data should be put in a Hashtable where the key indicates the cell (Point(col, row)). adding a row means than, to add the cell values of a row. the table will be updated by the model automatically. (ok, maybe you'll have to fire an event inside of the addRow method of your TableModel. see the swing tutorial.)
chantal
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic